(25)爬虫selenium滚动条的使用

from selenium import webdriver
from lxml import etree
from time import sleep
from random import randint
url ='https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&enc=utf-8&wq=%E6%89%8B%E6%9C%BA&pvid=4e03dd16c6b24f729048a28bcd2363f3'
edge = webdriver.Edge()
edge.get(url)
js='document.documentElement.scrollTop=10000'  
edge.execute_script(js)                           #selenium滚动条的使用
sleep(randint(3,7))
html = edge.page_source
e = etree.HTML(html)
prices = e.xpath('''//div[@class='gl-i-wrap']/div[@class='p-price']/strong/i/text()''')
names = e.xpath('''//div[@class='gl-i-wrap']/div/a[@target='_blank']/em/text()''')
for name,price in zip(names,prices):
    print('手机款式名称:',name,'——————其价格为——————:',price,'元')
posted @ 2020-08-02 18:12  kuanleung  阅读(12)  评论(0)    收藏  举报  来源