urllib中使用xpath

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)