selenium+PhantomJS 介绍、安装、使用:https://blog.csdn.net/qq_34288630/article/details/80342255
# coding=utf-8
import time
from selenium import webdriver
from bs4 import BeautifulSoup
url = "https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&wq=%E6%89%8B%E6%9C%BA&cid2=653&cid3=655&page=1&s=1&click=0"
driver = webdriver.PhantomJS()
driver.implicitly_wait(3)
driver.get(url)
# 模拟下滑到底部操作
for i in range(1,5):
js = "var q=document.documentElement.scrollTop=10000"
driver.execute_script(js)
#driver.execute("window.scrollTo(0,document.body.scrollHeight)")
time.sleep(9)
# 将加载好的页面源码给bs4解析
soup = BeautifulSoup(driver.page_source,"lxml")
# 进行信息的抽取(商品名称,价格)
goods_info = soup.select(".gl-item")
for info in goods_info:
title = info.select(".p-name.p-name-type-2 a")[0].text.strip()
price = info.select(".p-price")[0].text.strip()
print title
print price
driver.close()