|
为什么我取得xpath的值是“文思海辉”(如图),但是程序跑出来是其他公司呢import requestsfrom lxml import etreefrom spider.spiderv2 import spider2class spider3(spider2): def __init__(self): spider2.__init__(self,url) def position(self,res): doc = etree.HTML(res) element = doc.xpath('//*[@id="resultList"]/div[21]/span[1]/a/@title') return element def savedata(self,g): with open("data.txt","w") as file: file.writelines(str(g))if __name__ == '__main__': url = 'https://search.51job.com/list/020000,000000,0000,00,9,99,%25E8%25BD%25AF%25E4%25BB%25B6%25E6%25B5%258B%25E8%25AF%2595%25E5%25B7%25A5%25E7%25A8%258B%25E5%25B8%2588,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=' spiderobj = spider3() spiderobj.rurl = url r = spiderobj.submit_get(url) pos = spiderobj.position(r) print(pos) spiderobj.savedata(pos)
在学课程:
Python测试开发全栈核心课程 互联网测试工程师必修课
http://www.atstudy.com/course/1287
|
|