def get_products(): # 判断单个页面是否被加载出来 wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#mainsrp-itemlist .items .item'))) html = browser.page_source # 获取页面源代码,所有的 # 使用BS进行分析 soup = BeautifulSoup(html, 'lxml') items = soup.select('#mainsrp-itemlist .items .item') for item in items: image = item.select('.pic .img')[0]['data-src'] price = item.select('.price strong')[0].text deal = item.select('.deal-cnt')[0].text[:-3] title = item.select('.title')[0].text.strip() shop = item.select('.shop')[0].text.strip() location = item.select('.location')[0].text product = { 'image': image, 'price': price, 'deal': deal, 'title': title, 'shop': shop, 'location': location } save_text(product)