results = pd.DataFrame() # 爬取功能主函数 defpage_crawl(results): res = pd.Series() product_list = driver.find_elements_by_xpath('//*[@id="product-list"]') product_text = product_list[0].text text_list = product_text.split('¥') del text_list[0] print('len(text_list):', len(text_list)) iflen(text_list) != 120: print('超级会员异常,放弃!') else: print('没有超级会员异常,进行取数!') text_list_split = [ii.split('\n') for ii in text_list] prices = [ii[0] for ii in text_list_split] goods = [ii[1] for ii in text_list_split] counts = [com_count(ii[2]) for ii in text_list_split]
# 如果有错误,可以拥入这段代码,具体定位问题 # for ii in text_list_split: # print(ii[0], ii[1], ii[2])
for ii inrange(len(prices)): res.name = goods[ii] res['good_name'] = goods[ii] res['good_price'] = prices[ii] res['com_count'] = counts[ii]