Best Python code snippet using robotframework-anywherelibrary
renRen_func.py
Source:renRen_func.py
...16 result = {}17 for span in spans:18 for a in span.findAll('a'):19 key = a.get('href').split('/')[-2]20 name = a.get_text()21 result[key] = name22 jStr = json.dumps(result, ensure_ascii=False)23 with open('./json/rr_carType.json', 'w') as f:24 f.write(jStr)25 print("汽车类åä¿åå®æ¯ï¼")26def getCarLink(bsObj):27 """è·å汽车é¾æ¥"""28 items = bsObj.findAll('li', {'class': 'list-item'})29 result = []30 for item in items:31 href = item.a.get('href').split('/')32 if len(href) == 3:33 continue34 else:35 result.append({'city': href[1], 'href': href[-1]})36 return result37def getCarPage(bsObj):38 """è·å页é¢çæ大页ç æ°"""39 lis = bsObj.find('ul', {'class': 'pagination'}).findAll('li')40 tempArr = []41 for li in lis:42 tempArr.append(li.get_text())43 try:44 return int(tempArr[-2])45 except BaseException as err:46 print("转æ¢é¡µç åºéï¼é误æè¿°ï¼", err)47 return 048def getCity():49 """è·ååå¸ä¿¡æ¯ï¼è¿åä¸ä¸ªåå
¸"""50 with open("./json/rr_desCity.json", 'r', encoding='UTF-8') as f:51 res = json.loads(f.read())52 # for key in res:53 # print(key + ": " + res[key])54 return res55def getCarType():56 """è·å汽车信æ¯ï¼è¿åä¸ä¸ªåå
¸"""57 with open("./json/rr_carType.json", 'r', encoding='UTF-8') as f:58 res = json.loads(f.read())59 # for key in res:60 # print(key + ": " + res[key])61 return res62def getCarShortInfo(bsObj, i, j):63 """è·å汽车çç®ä»"""64 result = {}65 # 车å66 try:67 tempStr = bsObj.find('h1', {'class': 'title-name'}).get_text().replace('\n', '').strip()68 carname = ''69 for ch in tempStr:70 if ch.isdigit():71 carname += getRealNum(ch)72 else:73 carname += ch74 result['carname'] = carname75 except BaseException as err:76 print(i, j, "carname:", err)77 # 车主信æ¯78 try:79 result['owner'] = bsObj.find('h2', {'class': 'master-name'}).get_text().replace('å家-', '').replace('说车', '')80 except BaseException as err:81 print(i, j, "owner:", err)82 result['owner'] = "å
ç"83 # 车主åºä»·84 try:85 result['price'] = float(bsObj.find('p', {'class': 'price'}).get_text().replace('ä¸', ''))86 except BaseException as err:87 print(i, j, "price:", err)88 # é¦ä»89 try:90 result['firstPay'] = float(bsObj.find('p', {'class': 'money'}).get_text().replace('é¦ä»', '').replace('ä¸', ''))91 except BaseException as err:92 print(i, j, "firstPay:", err)93 result['firstPay'] = result['price']94 # ä¸çæ¶é´95 try:96 tempStr = bsObj.findAll('p', {'class': 'small-title'})[3].get_text().replace('ä¸ç', '')97 spsj = ''98 if tempStr == '车çæå¨å°':99 result['spsj'] = '-'100 else:101 for ch in tempStr:102 if ch.isdigit():103 spsj += getRealNum(ch)104 else:105 spsj += ch106 result['spsj'] = spsj107 except BaseException as err:108 print(i, j, 'spsj:',err)109 result['spsj'] = '-'110 # è¡é©¶éç¨111 try:112 result['xslc'] = float(bsObj.find('strong', {'class': 'car-summary'}).get_text().replace('ä¸å
¬é', ''))113 except BaseException as err:114 print(i, j, 'xslc:', err)115 result['xslc'] = 0116 # ä¸çå° ææ¾æ å åéç®± è¿æ·117 try:118 result['spd'] = bsObj.findAll('strong', {'class': 'car-summary'})[2].get_text()119 result['pfbz'] = bsObj.findAll('strong', {'class': 'car-summary'})[3].get_text()120 result['bsx'] = bsObj.findAll('strong', {'class': 'car-summary'})[4].get_text()121 result['gh'] = int(bsObj.findAll('strong', {'class': 'car-summary'})[5].get_text().replace('次', ''))122 except BaseException as err:123 print(i, j, 'spd:', err)124 result['spd'] = '-'125 result['pfbz'] = '-'126 result['bsx'] = '-'127 result['gh'] = 0128 # æé129 try:130 result['pl'] = float(bsObj.findAll('div', {'class': 'item-value'})[5].get_text())131 except BaseException as err:132 print(i, j, 'pl:', err)133 result['pl'] = -1134 # å¹´æ£å°ææ¶é´135 try:136 tempObj = bsObj.findAll('ul', {'class': 'info-about-car-content'})137 result['nj'] = tempObj[0].findAll('li')[1].get_text().replace('\xa0', '')138 result['syx'] = tempObj[0].findAll('li')[3].get_text().replace('\xa0', '')139 result['jqx'] = tempObj[1].findAll('li')[1].get_text().replace('\xa0', '')140 except BaseException as err:141 print(i, j, 'nj:', err)142 result['nj'] = '-'143 result['syx'] = '-'144 result['jqx'] = '-'145 return result146def getRealNum(char):147 """è·å¾æ£ççæ°å"""148 res = '0'149 try:150 num = char151 if num == '0':152 res = '0'153 elif num == '1':154 res = '5'155 elif num == '2':156 res = '6'157 elif num == '3':158 res = '3'159 elif num == '4':160 res = '1'161 elif num == '5':162 res = '2'163 elif num == '6':164 res = '7'165 elif num == '7':166 res = '4'167 elif num == '8':168 res = '9'169 else:170 res = '8'171 # if num == '0':172 # res = '0'173 # elif num == '1':174 # res = '2'175 # elif num == '2':176 # res = '1'177 # elif num == '3':178 # res = '4'179 # elif num == '4':180 # res = '3'181 # elif num == '5':182 # res = '8'183 # elif num == '6':184 # res = '6'185 # elif num == '7':186 # res = '7'187 # elif num == '8':188 # res = '5'189 # else:190 # res = '9'191 except BaseException as err:192 print("转æ¢çæ£çæ°åæ¶åºéï¼", err)193 return res194 finally:195 return res196def getCarBaseInfo(bsObj, valueNum):197 """è·å汽车çä¸é¡¹åºç¡åæ°"""198 valueobj = bsObj.findAll('div', {'class': 'item-value'})199 nameobj = bsObj.findAll('div', {'class': 'item-name'})200 arr = [182, 183, 184, 185, 186, 187, 190]201 body = ''202 zj = ''203 weight = ''204 if valueNum == 180:205 if nameobj[25].get_text().replace('\n', '').replace(' ', '') == 'æå°ç¦»å°é´é(mm)':206 body = valueobj[20].get_text().replace('\n', '').replace(' ', '')+'é¨'+ valueobj[21].get_text().replace('\n', '').replace(' ', '')+'座'+ valueobj[7].get_text().replace('\n', '').replace(' ', '')207 zj = valueobj[17].get_text().replace('\n', '').replace(' ', '')208 weight = valueobj[24].get_text().replace('\n', '').replace(' ', '')209 elif valueNum in arr:210 if nameobj[26].get_text().replace('\n', '').replace(' ', '') == 'æå°ç¦»å°é´é(mm)':211 body = valueobj[21].get_text().replace('\n', '').replace(' ', '')+'é¨'+ valueobj[22].get_text().replace('\n', '').replace(' ', '')+'座'+ valueobj[7].get_text().replace('\n', '').replace(' ', '')212 zj = valueobj[18].get_text().replace('\n', '').replace(' ', '')213 weight = valueobj[25].get_text().replace('\n', '').replace(' ', '')214 result = {215 # åå216 'company': valueobj[2].get_text().replace('\n', '').replace(' ', ''),217 # å¼æ218 'engine': valueobj[3].get_text().replace('\n', '').replace(' ', ''),219 # åéç®±220 'bsx': valueobj[4].get_text().replace('\n', '').replace(' ', ''),221 # 车身222 'body': body,223 # é¿å®½é«224 'carSize': valueobj[6].get_text().replace('\n', '').replace(' ', '').replace('*', '/'),225 # è½´è·226 'zj': zj,227 # æ´å¤è´¨é228 'weight': weight229 }230 return result231def getCarEngineInfo(bsObj, valueNum):232 """ç¨æ¥è·å汽车å¼æçåæ°"""233 valueobj = bsObj.findAll('div', {'class': 'item-value'})234 nameobj = bsObj.findAll('div', {'class': 'item-name'})235 arr = [182, 183, 184, 185, 186, 187, 190]236 jqxs = ''237 qg = ''238 zdml = 0239 zdnj = '0'240 rllx = ''241 rlbh = ''242 gyfs = ''243 pfbz = ''244 if valueNum == 180:245 if nameobj[47].get_text().replace('\n', '').replace(' ', '') == 'åé箱类å':246 jqxs = valueobj[28].get_text().replace('\n', '').replace(' ', '')247 qg = valueobj[29].get_text().replace('\n', '').replace(' ', '') + valueobj[30].get_text().replace('\n', '').replace(' ', '')248 zdml = int(valueobj[36].get_text().replace('\n', '').replace(' ', ''))249 zdnj = valueobj[39].get_text().replace('\n', '').replace(' ', '').split('-')250 rllx = valueobj[46].get_text().replace('\n', '').replace(' ', '')251 rlbh = valueobj[42].get_text().replace('\n', '').replace(' ', '')252 gyfs = valueobj[43].get_text().replace('\n', '').replace(' ', '')253 elif valueNum in arr:254 if nameobj[48].get_text().replace('\n', '').replace(' ', '') == 'ç¯ä¿æ å':255 jqxs = valueobj[29].get_text().replace('\n', '').replace(' ', '')256 qg = valueobj[30].get_text().replace('\n', '').replace(' ', '') + valueobj[31].get_text().replace('\n','').replace(' ', '')257 zdml = int(valueobj[37].get_text().replace('\n', '').replace(' ', ''))258 zdnj = valueobj[40].get_text().replace('\n', '').replace(' ', '').split('-')259 rllx = valueobj[47].get_text().replace('\n', '').replace(' ', '')260 rlbh = valueobj[43].get_text().replace('\n', '').replace(' ', '')261 gyfs = valueobj[44].get_text().replace('\n', '').replace(' ', '')262 pfbz =valueobj[48].get_text().replace('\n', '').replace(' ', '')263 # æ大æç©çå¤ç264 nj = '0'265 if len(zdnj) == 2:266 nj = zdnj[1]267 elif len(zdnj) == 1:268 nj = zdnj[0]269 else:270 nj = '0'271 result = {272 # æé273 'pl': valueobj[5].get_text().replace('\n', '').replace(' ', ''),274 # è¿æ°æ¹å¼275 'jqxs': jqxs,276 # # æ°ç¼¸277 'qg': qg,278 # æ大马å279 'zdml': zdml,280 # æ大æç©281 'zdnj': int(nj),282 # çæç±»å283 'rllx': rllx,284 # çææ å·285 'rlbh': rlbh,286 # ä¾æ²¹æ¹å¼287 'gyfs': gyfs,288 # ææ¾æ å289 'pfbz': pfbz290 }291 return result292def getCarSafeInfo(bsObj, valueNum):293 """è·å汽车å®å
¨é
ç½®åæ°"""294 valueobj = bsObj.findAll('div', {'class': 'item-value'})295 nameobj = bsObj.findAll('div', {'class': 'item-name'})296 arr = [184, 185, 186, 187, 190]297 aqqn = 'æ /æ '298 tyjc = 'æ '299 cnzks = 'æ '300 zyjk = 'æ '301 wysqd = 'æ '302 fbsxt = 'æ '303 if valueNum == 180:304 if nameobj[84].get_text().replace('\n', '').replace(' ', '') == 'é²æ±æ»å¶å¨ç³»ç»':305 aqqn = valueobj[62].get_text().replace('\n', '').replace(' ', '') + '/' + valueobj[63].get_text().replace('\n', '').replace(' ', '')306 tyjc = valueobj[69].get_text().replace('\n', '').replace(' ', '')307 cnzks = valueobj[72].get_text().replace('\n', '').replace(' ', '')308 # zyjk 没æï¼ é»è®¤'æ '309 wysqd = valueobj[74].get_text().replace('\n', '').replace(' ', '')310 fbsxt = valueobj[84].get_text().replace('\n', '').replace(' ', '')311 elif valueNum == 182:312 if nameobj[86].get_text().replace('\n', '').replace(' ', '') == 'é²æ±æ»å¶å¨ç³»ç»':313 aqqn = valueobj[63].get_text().replace('\n', '').replace(' ', '') + '/' + valueobj[64].get_text().replace('\n', '').replace(' ', '')314 tyjc = valueobj[70].get_text().replace('\n', '').replace(' ', '')315 cnzks = valueobj[74].get_text().replace('\n', '').replace(' ', '')316 zyjk = valueobj[73].get_text().replace('\n', '').replace(' ', '')317 wysqd = valueobj[76].get_text().replace('\n', '').replace(' ', '')318 fbsxt = valueobj[86].get_text().replace('\n', '').replace(' ', '')319 elif valueNum == 183:320 if nameobj[87].get_text().replace('\n', '').replace(' ', '') == 'é²æ±æ»å¶å¨ç³»ç»':321 aqqn = valueobj[64].get_text().replace('\n', '').replace(' ', '') + '/' + valueobj[65].get_text().replace('\n', '').replace(' ', '')322 tyjc = valueobj[71].get_text().replace('\n', '').replace(' ', '')323 cnzks = valueobj[75].get_text().replace('\n', '').replace(' ', '')324 zyjk = valueobj[74].get_text().replace('\n', '').replace(' ', '')325 wysqd = valueobj[77].get_text().replace('\n', '').replace(' ', '')326 fbsxt = valueobj[87].get_text().replace('\n', '').replace(' ', '')327 elif valueNum in arr:328 if nameobj[88].get_text().replace('\n', '').replace(' ', '') == 'é²æ±æ»å¶å¨ç³»ç»':329 aqqn = valueobj[65].get_text().replace('\n', '').replace(' ', '') + '/' + valueobj[66].get_text().replace('\n', '').replace(' ', '')330 tyjc = valueobj[72].get_text().replace('\n', '').replace(' ', '')331 cnzks = valueobj[76].get_text().replace('\n', '').replace(' ', '')332 zyjk = valueobj[75].get_text().replace('\n', '').replace(' ', '')333 wysqd = valueobj[78].get_text().replace('\n', '').replace(' ', '')334 fbsxt = valueobj[88].get_text().replace('\n', '').replace(' ', '')335 result = {336 # 主å¯é©¾é©¶å®å
¨æ°å337 'aqqn': aqqn,338 # èåçæµ339 'tyjc': tyjc,340 # 车å
ä¸æ§é341 'cnzks': cnzks,342 # å¿ç«¥åº§æ¤
æ¥å£343 'zyjk': zyjk,344 # æ é¥åå¯å¨345 'wysqd': wysqd,346 # é²æ±æ»ç³»ç»347 'fbsxt': fbsxt,348 }349 return result350def getCarOutsideInfo(bsObj, valueNum):351 """ç¨æ¥è·å汽车å¤é¨é
ç½®çåæ°"""352 valueobj = bsObj.findAll('div', {'class': 'item-value'})353 nameobj = bsObj.findAll('div', {'class': 'item-name'})354 arr = []355 ddtc = 'æ '356 qjtc = 'æ '357 ddxhm = 'æ '358 qhddcc = 'æ '359 ddtj = 'æ '360 hsjjr = 'æ '361 if valueNum == 180:362 if nameobj[153].get_text().replace('\n', '').replace(' ', '') == 'åè§éå ç':363 ddtc = valueobj[88].get_text().replace('\n', '').replace(' ', '')364 qjtc = valueobj[89].get_text().replace('\n', '').replace(' ', '')365 ddxhm = valueobj[92].get_text().replace('\n', '').replace(' ', '')366 qhddcc = valueobj[148].get_text().replace('\n', '').replace(' ', '')+'/'+valueobj[149].get_text().replace('\n', '').replace(' ', '')367 ddtj = valueobj[152].get_text().replace('\n', '').replace(' ', '')368 hsjjr = valueobj[153].get_text().replace('\n', '').replace(' ', '')369 elif valueNum == 182:370 if nameobj[155].get_text().replace('\n', '').replace(' ', '') == 'åè§éå ç':371 ddtc = valueobj[91].get_text().replace('\n', '').replace(' ', '')372 qjtc = valueobj[92].get_text().replace('\n', '').replace(' ', '')373 ddxhm = valueobj[95].get_text().replace('\n', '').replace(' ', '')374 qhddcc = valueobj[150].get_text().replace('\n', '').replace(' ', '')+'/'+valueobj[151].get_text().replace('\n', '').replace(' ', '')375 ddtj = valueobj[154].get_text().replace('\n', '').replace(' ', '')376 hsjjr = valueobj[155].get_text().replace('\n', '').replace(' ', '')377 elif valueNum == 183:378 if nameobj[156].get_text().replace('\n', '').replace(' ', '') == 'åè§éå ç':379 ddtc = valueobj[92].get_text().replace('\n', '').replace(' ', '')380 qjtc = valueobj[93].get_text().replace('\n', '').replace(' ', '')381 ddxhm = valueobj[96].get_text().replace('\n', '').replace(' ', '')382 qhddcc = valueobj[151].get_text().replace('\n', '').replace(' ', '')+'/'+valueobj[152].get_text().replace('\n', '').replace(' ', '')383 ddtj = valueobj[155].get_text().replace('\n', '').replace(' ', '')384 hsjjr = valueobj[156].get_text().replace('\n', '').replace(' ', '')385 elif valueNum == 184:386 if nameobj[157].get_text().replace('\n', '').replace(' ', '') == 'åè§éå ç':387 ddtc = valueobj[93].get_text().replace('\n', '').replace(' ', '')388 qjtc = valueobj[94].get_text().replace('\n', '').replace(' ', '')389 ddxhm = valueobj[97].get_text().replace('\n', '').replace(' ', '')390 qhddcc = valueobj[152].get_text().replace('\n', '').replace(' ', '')+'/'+valueobj[153].get_text().replace('\n', '').replace(' ', '')391 ddtj = valueobj[156].get_text().replace('\n', '').replace(' ', '')392 hsjjr = valueobj[157].get_text().replace('\n', '').replace(' ', '')393 elif valueNum == 185:394 if nameobj[158].get_text().replace('\n', '').replace(' ', '') == 'åè§éå ç':395 ddtc = valueobj[93].get_text().replace('\n', '').replace(' ', '')396 qjtc = valueobj[94].get_text().replace('\n', '').replace(' ', '')397 ddxhm = valueobj[97].get_text().replace('\n', '').replace(' ', '')398 qhddcc = valueobj[153].get_text().replace('\n', '').replace(' ', '')+'/'+valueobj[154].get_text().replace('\n', '').replace(' ', '')399 ddtj = valueobj[157].get_text().replace('\n', '').replace(' ', '')400 hsjjr = valueobj[158].get_text().replace('\n', '').replace(' ', '')401 elif valueNum == 186:402 if nameobj[159].get_text().replace('\n', '').replace(' ', '') == 'åè§éå ç':403 ddtc = valueobj[93].get_text().replace('\n', '').replace(' ', '')404 qjtc = valueobj[94].get_text().replace('\n', '').replace(' ', '')405 ddxhm = valueobj[97].get_text().replace('\n', '').replace(' ', '')406 qhddcc = valueobj[154].get_text().replace('\n', '').replace(' ', '')+'/'+valueobj[155].get_text().replace('\n', '').replace(' ', '')407 ddtj = valueobj[158].get_text().replace('\n', '').replace(' ', '')408 hsjjr = valueobj[159].get_text().replace('\n', '').replace(' ', '')409 elif valueNum == 187:410 if nameobj[160].get_text().replace('\n', '').replace(' ', '') == 'åè§éå ç':411 ddtc = valueobj[93].get_text().replace('\n', '').replace(' ', '')412 qjtc = valueobj[94].get_text().replace('\n', '').replace(' ', '')413 ddxhm = valueobj[97].get_text().replace('\n', '').replace(' ', '')414 qhddcc = valueobj[155].get_text().replace('\n', '').replace(' ', '')+'/'+valueobj[156].get_text().replace('\n', '').replace(' ', '')415 ddtj = valueobj[159].get_text().replace('\n', '').replace(' ', '')416 hsjjr = valueobj[160].get_text().replace('\n', '').replace(' ', '')417 elif valueNum == 190:418 if nameobj[163].get_text().replace('\n', '').replace(' ', '') == 'åè§éå ç':419 ddtc = valueobj[94].get_text().replace('\n', '').replace(' ', '')420 qjtc = valueobj[95].get_text().replace('\n', '').replace(' ', '')421 ddxhm = valueobj[98].get_text().replace('\n', '').replace(' ', '')422 qhddcc = valueobj[158].get_text().replace('\n', '').replace(' ', '')+'/'+valueobj[159].get_text().replace('\n', '').replace(' ', '')423 ddtj = valueobj[162].get_text().replace('\n', '').replace(' ', '')424 hsjjr = valueobj[163].get_text().replace('\n', '').replace(' ', '')425 result = {426 # çµå¨è½¦çª427 'ddtc': ddtc,428 # å
¨æ¯å¤©çª429 'qjtc': qjtc,430 # çµå¨å¸åé¨431 'ddxhm': ddxhm,432 # ååçµå¨è½¦çª433 'qhddcc': qhddcc,434 # åè§éçµå¨è°è435 'ddtj': ddtj,436 # åè§éå ç437 'hsjjr': hsjjr438 }439 return result440def getCarInsideInfo(bsObj, valueNum):441 """è·å汽车å
é¨é
置信æ¯"""442 valueobj = bsObj.findAll('div', {'class': 'item-value'})443 nameobj = bsObj.findAll('div', {'class': 'item-name'})444 fxp = 'æ '445 dsxh = 'æ '446 kt = 'æ é
'447 GPS = 'æ '448 if valueNum == 180:449 if nameobj[130].get_text().replace('\n', '').replace(' ', '') == 'GPS导èªç³»ç»':450 fxp = valueobj[98].get_text().replace('\n', '').replace(' ', '')451 dsxh = valueobj[101].get_text().replace('\n', '').replace(' ', '')452 GPS = valueobj[130].get_text().replace('\n', '').replace(' ', '')453 elif valueNum == 182:454 if nameobj[131].get_text().replace('\n', '').replace(' ', '') == 'GPS导èªç³»ç»':455 fxp = valueobj[101].get_text().replace('\n', '').replace(' ', '')456 dsxh = valueobj[104].get_text().replace('\n', '').replace(' ', '')457 GPS = valueobj[131].get_text().replace('\n', '').replace(' ', '')458 elif valueNum == 183:459 if nameobj[134].get_text().replace('\n', '').replace(' ', '') == 'GPS导èªç³»ç»':460 fxp = valueobj[102].get_text().replace('\n', '').replace(' ', '')461 dsxh = valueobj[105].get_text().replace('\n', '').replace(' ', '')462 GPS = valueobj[134].get_text().replace('\n', '').replace(' ', '')463 elif valueNum == 184:464 if nameobj[133].get_text().replace('\n', '').replace(' ', '') == 'GPS导èªç³»ç»':465 fxp = valueobj[103].get_text().replace('\n', '').replace(' ', '')466 dsxh = valueobj[106].get_text().replace('\n', '').replace(' ', '')467 GPS = valueobj[133].get_text().replace('\n', '').replace(' ', '')468 elif valueNum == 185:469 if nameobj[134].get_text().replace('\n', '').replace(' ', '') == 'GPS导èªç³»ç»':470 fxp = valueobj[103].get_text().replace('\n', '').replace(' ', '')471 dsxh = valueobj[106].get_text().replace('\n', '').replace(' ', '')472 GPS = valueobj[134].get_text().replace('\n', '').replace(' ', '')473 elif valueNum == 186 or valueNum == 187:474 if nameobj[135].get_text().replace('\n', '').replace(' ', '') == 'GPS导èªç³»ç»':475 fxp = valueobj[103].get_text().replace('\n', '').replace(' ', '')476 dsxh = valueobj[106].get_text().replace('\n', '').replace(' ', '')477 GPS = valueobj[135].get_text().replace('\n', '').replace(' ', '')478 elif valueNum == 190:479 if nameobj[136].get_text().replace('\n', '').replace(' ', '') == 'GPS导èªç³»ç»':480 fxp = valueobj[104].get_text().replace('\n', '').replace(' ', '')481 dsxh = valueobj[107].get_text().replace('\n', '').replace(' ', '')482 GPS = valueobj[136].get_text().replace('\n', '').replace(' ', '')483 result = {484 # å¤åè½æ¹åç485 'fxp': fxp,486 # å®éå·¡èª487 'dsxh': dsxh,488 # 空è°489 'kt': kt,490 # GPS491 'GPS': GPS492 }493 return result494def getCarStoppingInfo(bsObj, valueNum):495 """ç¨æ¥è·å汽车çåºçåå¶å¨ä¿¡æ¯"""496 # åæ°æ 驱å¨æ¹å¼ å©åæ¹å¼ åæ¬æç±»å åæ¬æç±»å åå¶å¨ç±»å åå¶å¨ç±»å åè½®èè§æ ¼ åè½®èè§æ ¼497 valueobj = bsObj.findAll('div', {'class': 'item-value'})498 nameobj = bsObj.findAll('div', {'class': 'item-name'})499 arr = [184, 185, 186, 187, 190]500 qdfs = ''501 zlfs = ''502 qxglx = ''503 hxglx = ''504 qzdlx = ''505 hzdlx = ''506 qltgg = ''507 hltgg = ''508 if valueNum == 180:509 if nameobj[60].get_text().replace('\n', '').replace(' ', '') == 'åè½®èè§æ ¼':510 qdfs = valueobj[49].get_text().replace('\n', '').replace(' ', '')511 zlfs = valueobj[50].get_text().replace('\n', '').replace(' ', '')512 qxglx = valueobj[52].get_text().replace('\n', '').replace(' ', '')513 hxglx = valueobj[53].get_text().replace('\n', '').replace(' ', '')514 qzdlx = valueobj[56].get_text().replace('\n', '').replace(' ', '')515 hzdlx = valueobj[57].get_text().replace('\n', '').replace(' ', '')516 qltgg = valueobj[59].get_text().replace('\n', '').replace(' ', '')517 hltgg = valueobj[60].get_text().replace('\n', '').replace(' ', '')518 elif valueNum == 182:519 if nameobj[61].get_text().replace('\n', '').replace(' ', '') == 'åè½®èè§æ ¼':520 qdfs = valueobj[52].get_text().replace('\n', '').replace(' ', '')521 zlfs = valueobj[53].get_text().replace('\n', '').replace(' ', '')522 qxglx = valueobj[55].get_text().replace('\n', '').replace(' ', '')523 hxglx = valueobj[56].get_text().replace('\n', '').replace(' ', '')524 qzdlx = valueobj[57].get_text().replace('\n', '').replace(' ', '')525 hzdlx = valueobj[58].get_text().replace('\n', '').replace(' ', '')526 qltgg = valueobj[60].get_text().replace('\n', '').replace(' ', '')527 hltgg = valueobj[61].get_text().replace('\n', '').replace(' ', '')528 elif valueNum == 183:529 if nameobj[62].get_text().replace('\n', '').replace(' ', '') == 'åè½®èè§æ ¼':530 qdfs = valueobj[51].get_text().replace('\n', '').replace(' ', '')531 zlfs = valueobj[52].get_text().replace('\n', '').replace(' ', '')532 qxglx = valueobj[54].get_text().replace('\n', '').replace(' ', '')533 hxglx = valueobj[55].get_text().replace('\n', '').replace(' ', '')534 qzdlx = valueobj[58].get_text().replace('\n', '').replace(' ', '')535 hzdlx = valueobj[59].get_text().replace('\n', '').replace(' ', '')536 qltgg = valueobj[61].get_text().replace('\n', '').replace(' ', '')537 hltgg = valueobj[62].get_text().replace('\n', '').replace(' ', '')538 elif valueNum in arr:539 if nameobj[63].get_text().replace('\n', '').replace(' ', '') == 'åè½®èè§æ ¼':540 qdfs = valueobj[52].get_text().replace('\n', '').replace(' ', '')541 zlfs = valueobj[53].get_text().replace('\n', '').replace(' ', '')542 qxglx = valueobj[55].get_text().replace('\n', '').replace(' ', '')543 hxglx = valueobj[56].get_text().replace('\n', '').replace(' ', '')544 qzdlx = valueobj[59].get_text().replace('\n', '').replace(' ', '')545 hzdlx = valueobj[60].get_text().replace('\n', '').replace(' ', '')546 qltgg = valueobj[62].get_text().replace('\n', '').replace(' ', '')547 hltgg = valueobj[63].get_text().replace('\n', '').replace(' ', '')548 result = {549 # 驱å¨æ¹å¼550 'qdfs': qdfs,551 # å©åæ¹å¼552 'zlfs': zlfs,553 # åæ¬æç±»å554 'qxglx': qxglx,555 # åæ¬æç±»å556 'hxglx': hxglx,557 # åå¶å¨ç±»å558 'qzdlx': qzdlx,559 # åå¶å¨ç±»å560 'hzdlx': hzdlx,561 # åè½®èè§æ ¼562 'qltgg': qltgg.split('R')[0] + ' R' + qltgg.split('R')[1],563 # åè½®èè§æ ¼564 'hltgg': hltgg.split('R')[0] + ' R' + hltgg.split('R')[1]565 }566 return result567def getCarPic(bsObj):568 """ç¨æ¥è·å汽车çç
§ç"""569 # ç
§çå为 车è¾å¤è§ 车è¾å
饰 åå¨æºååºç570 pics = bsObj.findAll('li', {'class': 'clk'})571 result = {572 'outside': '',573 'inside': '',574 'engine': ''575 }576 try:577 # åé¢13å¼ ä¸ºå¤é¨ï¼å4å¼ ä¸ºåå¨æºååºçï¼ ä¸é´ä¸ºå
饰578 outside = ''579 inside = ''580 engine = ''581 for i in range(len(pics)):582 temp = pics[i].a.img.get('src')+'#'583 if i < 13:584 outside += temp585 elif i < (len(pics) - 4):586 inside += temp587 else:588 engine += temp589 return {590 'outside': outside,591 'inside': inside,592 'engine': engine593 }594 except BaseException as err:595 print("è·åç
§çæ¶åºéï¼é误æ述为ï¼", err)596 return result597def getNowTime():598 intdata = time.time()599 strdata = str(intdata).split('.')600 try:601 findata = strdata[0]+strdata[1]602 except BaseException as err:603 print("è·åå½åæ¶é´å¤±è´¥ï¼")604 print("é误æè¿°ï¼", err)605 findata = str(random.randint(1, 100000))606 return findata607def isElectricCar(bsObj, carUrl, valueNum):608 """å¤æ车è¾æ¯å¦æ¯çµå¨è½¦"""609 valueobj = bsObj.findAll('div', {'class': 'item-value'})610 nameobj = bsObj.findAll('div', {'class': 'item-name'})611 rl = ''612 arr = [182, 183, 184, 185, 186, 187, 190]613 if valueNum in arr:614 if nameobj[47].get_text().replace('\n', '').replace(' ', '') == 'ç油形å¼':615 rl = valueobj[47].get_text().replace('\n', '').replace(' ', '')616 if rl == '纯çµå¨':617 return False618 else:619 return True620 else:621 print("对åºé误ï¼", carUrl)622 return False623 elif valueNum == 180:624 if nameobj[46].get_text().replace('\n', '').replace(' ', '') == 'ç油形å¼':625 rl = valueobj[46].get_text().replace('\n', '').replace(' ', '')626 if rl == '纯çµå¨':627 return False628 else:629 return True630 else:631 print("对åºé误ï¼", carUrl)632 return False633def saveCarAllInfo(finBsObj, i, index, cities, city, carTypes, carType, valueNum, carUrl):634 """ç¨æ¥åå¨æ±½è½¦çææä¿¡æ¯"""635 try:636 nowTime = getNowTime()637 # è·å汽车åºæ¬ä¿¡æ¯638 shortInfo = getCarShortInfo(finBsObj, i, index)639 shortInfo['id'] = nowTime...
event2mind_test.py
Source:event2mind_test.py
...5from allennlp.common.util import ensure_list6from allennlp.common.testing import AllenNlpTestCase7from allennlp.data.fields import TextField8from allennlp.data.instance import Instance9def get_text(key: str, instance: Instance):10 return [t.text for t in cast(TextField, instance.fields[key]).tokens]11class TestEvent2MindDatasetReader:12 @pytest.mark.parametrize("lazy", (True, False))13 def test_read(self, lazy):14 reader = Event2MindDatasetReader(lazy=lazy)15 instances = reader.read(16 str(AllenNlpTestCase.FIXTURES_ROOT / 'data' / 'event2mind_small.csv')17 )18 instances = ensure_list(instances)19 assert len(instances) == 1320 instance = instances[0]21 assert get_text("source", instance) == ["@start@", "it", "is", "personx", "'s",22 "favorite", "animal", "@end@"]23 assert get_text("xintent", instance) == ["@start@", "none", "@end@"]24 assert get_text("xreact", instance) == ["@start@", "excited", "to", "see", "it", "@end@"]25 assert get_text("oreact", instance) == ["@start@", "none", "@end@"]26 instance = instances[3]27 assert get_text("source", instance) == ["@start@", "personx", "drives",28 "persony", "'s", "truck", "@end@"]29 assert get_text("xintent", instance) == ["@start@", "move", "@end@"]30 assert get_text("xreact", instance) == ["@start@", "grateful", "@end@"]31 assert get_text("oreact", instance) == ["@start@", "charitable", "@end@"]32 instance = instances[4]33 assert get_text("source", instance) == ["@start@", "personx", "drives",34 "persony", "'s", "truck", "@end@"]35 assert get_text("xintent", instance) == ["@start@", "move", "@end@"]36 assert get_text("xreact", instance) == ["@start@", "grateful", "@end@"]37 # Interestingly, taking all combinations doesn't make much sense if the38 # original source is ambiguous.39 assert get_text("oreact", instance) == ["@start@", "enraged", "@end@"]40 instance = instances[10]41 assert get_text("source", instance) == ["@start@", "personx", "drives",42 "persony", "'s", "truck", "@end@"]43 assert get_text("xintent", instance) == ["@start@", "steal", "@end@"]44 assert get_text("xreact", instance) == ["@start@", "guilty", "@end@"]45 assert get_text("oreact", instance) == ["@start@", "enraged", "@end@"]46 instance = instances[11]47 assert get_text("source", instance) == ["@start@", "personx", "gets", "persony",48 "'s", "mother", "@end@"]49 assert get_text("xintent", instance) == ["@start@", "helpful", "@end@"]50 assert get_text("xreact", instance) == ["@start@", "useful", "@end@"]51 assert get_text("oreact", instance) == ["@start@", "grateful", "@end@"]52 instance = instances[12]53 assert get_text("source", instance) == ["@start@", "personx", "drives",54 "persony", "'s", "truck", "@end@"]55 assert get_text("xintent", instance) == ["@start@", "for", "fun", "@end@"]56 assert get_text("xreact", instance) == ["@start@", "happy", "@end@"]57 assert get_text("oreact", instance) == ["@start@", "like", "a", "good", "friend", "@end@"]58 @pytest.mark.parametrize("lazy", (True, False))59 def test_read_with_dummy_instances_for_vocab_generation(self, lazy):60 reader = Event2MindDatasetReader(lazy=lazy, dummy_instances_for_vocab_generation=True)61 instances = reader.read(62 str(AllenNlpTestCase.FIXTURES_ROOT / 'data' / 'event2mind_small.csv')63 )64 instances = ensure_list(instances)65 assert len(instances) == 2166 instance = instances[0]67 assert get_text("source", instance) == ["@start@", "it", "is", "personx", "'s",68 "favorite", "animal", "@end@"]69 assert get_text("xintent", instance) == ["@start@", "none", "@end@"]70 assert get_text("xreact", instance) == ["@start@", "none", "@end@"]71 assert get_text("oreact", instance) == ["@start@", "none", "@end@"]72 instance = instances[6]73 assert get_text("source", instance) == ["@start@", "personx", "drives",74 "persony", "'s", "truck", "@end@"]75 assert get_text("xintent", instance) == ["@start@", "none", "@end@"]76 assert get_text("xreact", instance) == ["@start@", "none", "@end@"]77 assert get_text("oreact", instance) == ["@start@", "none", "@end@"]78 instance = instances[7]79 assert get_text("source", instance) == ["@start@", "none", "@end@"]80 assert get_text("xintent", instance) == ["@start@", "move", "@end@"]81 assert get_text("xreact", instance) == ["@start@", "none", "@end@"]82 assert get_text("oreact", instance) == ["@start@", "none", "@end@"]83 instance = instances[9]84 assert get_text("source", instance) == ["@start@", "none", "@end@"]85 assert get_text("xintent", instance) == ["@start@", "none", "@end@"]86 assert get_text("xreact", instance) == ["@start@", "grateful", "@end@"]87 assert get_text("oreact", instance) == ["@start@", "none", "@end@"]88 instance = instances[11]89 assert get_text("source", instance) == ["@start@", "none", "@end@"]90 assert get_text("xintent", instance) == ["@start@", "none", "@end@"]91 assert get_text("xreact", instance) == ["@start@", "none", "@end@"]92 assert get_text("oreact", instance) == ["@start@", "charitable", "@end@"]93 instance = instances[13]94 assert get_text("source", instance) == ["@start@", "personx", "gets", "persony",95 "'s", "mother", "@end@"]96 assert get_text("xintent", instance) == ["@start@", "none", "@end@"]97 assert get_text("xreact", instance) == ["@start@", "none", "@end@"]...
tick_add_def.py
Source:tick_add_def.py
2 if axis == 'x':3 if '(_)' in add:4 if add[-3:] == '(_)':5 ax.set_xticks(ax.get_xticks())6 ax.set_xticklabels(['({}{})'.format(add[:-3], x.get_text()[1:]) if '-' in x.get_text()[0] else '{}{}'.format(add[:-3], x.get_text()) for x in ax.get_xticklabels()])7 elif add[:3] == '(_)':8 ax.set_xticks(ax.get_xticks())9 ax.set_xticklabels(['({}{})'.format(x.get_text()[1:], add[3:]) if '-' in x.get_text()[0] else '{}{}'.format(x.get_text(), add[3:]) for x in ax.get_xticklabels()])10 else: 11 ax.set_xticks(ax.get_xticks())12 ax.set_xticklabels(['({}{}{})'.format(add.split('(_)')[0], x.get_text()[1:], add.split('(_)')[-1]) if '-' in x.get_text()[0] else '{}{}{}'.format(add.split('(_)')[0], x.get_text(), add.split('(_)')[-1]) for x in ax.get_xticklabels()])13 elif '_' in add:14 if add[-1] == '_':15 ax.set_xticks(ax.get_xticks())16 ax.set_xticklabels(['-{}{}'.format(add[:-1], x.get_text()[1:]) if '-' in x.get_text()[0] else '{}{}'.format(add[:-1], x.get_text()) for x in ax.get_xticklabels()])17 elif add[0] == '_':18 ax.set_xticks(ax.get_xticks())19 ax.set_xticklabels(['{}{}'.format(x.get_text(), add[1:]) for x in ax.get_xticklabels()])20 else: 21 ax.set_xticks(ax.get_xticks())22 ax.set_xticklabels(['-{}{}{}'.format(add.split('_')[0], x.get_text()[1:], add.split('_')[-1]) if '-' in x.get_text()[0] else '{}{}{}'.format(add.split('_')[0], x.get_text(), add.split('_')[-1]) for x in ax.get_xticklabels()])23 else:24 raise Exception('Unknown tick add argument!')25 elif axis == 'y':26 if '(_)' in add:27 if add[-3:] == '(_)':28 ax.set_yticks(ax.get_yticks())29 ax.set_yticklabels(['({}{})'.format(add[:-3], y.get_text()[1:]) if '-' in y.get_text()[0] else '{}{}'.format(add[:-3], y.get_text()) for y in ax.get_yticklabels()])30 elif add[:3] == '(_)':31 ax.set_yticks(ax.get_yticks())32 ax.set_yticklabels(['({}{})'.format(y.get_text()[1:], add[3:]) if '-' in y.get_text()[0] else '{}{}'.format(y.get_text(), add[3:]) for y in ax.get_yticklabels()])33 else: 34 ax.set_yticks(ax.get_yticks())35 ax.set_yticklabels(['({}{}{})'.format(add.split('(_)')[0], y.get_text()[1:], add.split('(_)')[-1]) if '-' in y.get_text()[0] else '{}{}{}'.format(add.split('(_)')[0], y.get_text(), add.split('(_)')[-1]) for y in ax.get_yticklabels()])36 elif '_' in add:37 if add[-1] == '_':38 ax.set_yticks(ax.get_yticks())39 ax.set_yticklabels(['-{}{}'.format(add[:-1], y.get_text()[1:]) if '-' in y.get_text()[0] else '{}{}'.format(add[:-1], y.get_text()) for y in ax.get_yticklabels()])40 elif add[0] == '_':41 ax.set_yticks(ax.get_yticks())42 ax.set_yticklabels(['{}{}'.format(y.get_text(), add[1:]) for y in ax.get_yticklabels()])43 else: 44 ax.set_yticks(ax.get_yticks())45 ax.set_yticklabels(['-{}{}{}'.format(add.split('_')[0], y.get_text()[1:], add.split('_')[-1]) if '-' in y.get_text()[0] else '{}{}{}'.format(add.split('_')[0], y.get_text(), add.split('_')[-1]) for y in ax.get_yticklabels()])46 else:47 raise Exception('Unknown tick add argument!')48 else:49 raise Exception('Unsupported axis!')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!