import requests
from lxml import html
def spider_id(sn):
""" 爬取京东商城的图书信息 """
url = 'https://search.jd.com/Search?keyword={0}'.format(sn)
#获取HTML信息
html_data = requests.get(url).text
#获取xpath对象
selector = html.fromstring(html_data)
#寻找书本列表
ul_list = selector.xpath('//div[@id="J_goodsList"]/ul/li')
print(len(ul_list))
if __name__ == '__main__':
sn = '9787115428028'
spider_id(sn)