Py学习  »  web工具

新手求助爬虫简单问题

janson.lixs • 6 年前 • 1548 次点击  

如何用python从以下代码中,获取到src后面的地址,感谢。 <span class="yanzhengimg"> <img id="login_verify_code_img" src="/bis/user/verifyCodeImg?0.0544816582801837"> </span>

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/3248
 
1548 次点击  
文章 [ 1 ]  |  最新文章 6 年前
1160440782
Reply   •   1 楼
1160440782    6 年前

利用xpath抓取

from lxml.html import fromstring

html = '''<span class="yanzhengimg"> <img id="login_verify_code_img" src="/bis/user/verifyCodeImg?0.0544816582801837"> </span>'''

tree = fromstring(html)

src = tree.xpath('//img[@id="login_verify_code_img"]/@src')[0]