美文网首页
urllib中使用xpath

urllib中使用xpath

作者: tonyemail_st | 来源:发表于2017-11-04 09:50 被阅读0次
from lxml import etree


filename = 'douban.txt'
cookie = cookielib.MozillaCookieJar(filename)
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
response = opener.open("https://accounts.douban.com/login")
cookie.save(ignore_expires=True, ignore_discard=True)

data = response.read()
treedata = etree.HTML(data)
captcha = treedata.xpath("//img[@id='captcha_image']/@src")

相关文章

网友评论

      本文标题:urllib中使用xpath

      本文链接:https://www.haomeiwen.com/subject/hclfmxtx.html