How to use get_text method in AutoItDriverServer

Best Python code snippet using AutoItDriverServer_python

renRen_func.py

Source:renRen_func.py Github

copy

Full Screen

...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...

Full Screen

Full Screen

event2mind_test.py

Source:event2mind_test.py Github

copy

Full Screen

...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@"]...

Full Screen

Full Screen

tick_add_def.py

Source:tick_add_def.py Github

copy

Full Screen

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!')...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run AutoItDriverServer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful