Splash简单应用

jd->iphone

import requests
from lxml import etree
#
search_key = 'iphone'
jd_url = "https://search.jd.com/Search?keyword={}&enc=utf-8&wq={}&pvid=1a54a615e86645f8aaf828df04a78b27".format(
    search_key, search_key)
url = 'http://10.63.32.49:8050/render.html?url={}'.format(jd_url)
print(url)
# http://10.63.32.49:8050/render.html?url=https://search.jd.com/Search?keyword=iphone&enc=utf-8&wq=iphone&pvid=1a54a615e86645f8aaf828df04a78b27
r = requests.get(url)
selector = etree.HTML(r.text)
li_list = selector.xpath('//div[@id="J_goodsList"]/ul/li')
for li in li_list:
    price, = li.xpath('.//div[@class="p-price"]//i/text()')
    print(price)

 

posted @ 2019-11-18 12:30  市丸银  阅读(143)  评论(0编辑  收藏  举报