import requests
from lxml import etree
url = 'https://search.51job.com/list/010000,000000,0000,00,9,99,%s,2,1.html' #参数,get请求可给可不给,不给参数按默认计算'?lang=c&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare='
if __name__ == '__main__': key = input('请输入查询工作的关键字:') q = url%(key) response = requests.get(q) #response.encoding = 'gbk' #print(response.text) #乱码原因:编码问题 默认: utf-8 text = response.text tree = etree.HTML(text) divs = tree.xpath('//div[@class="in"]') #divs = tree.xpath('//*') #divs=tree.xpath('.//div[@class="e"]') print(len(divs)) #print(divs) xpath什么标签数量都不对,为什么数量不对啊,原网站https://search.51job.com/list/010000,000000,0000,00,9,99,%25E4%25BA%25BA%25E5%25B7%25A5%25E6%2599%25BA%25E8%2583%25BD,2,1.html?lang=c&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare=
- 复制链接
- 举报