【发布时间】:2017-04-27 18:03:38
【问题描述】:
我设法得到了我想要的所有东西,除了我想下载这个图像到当前目录这是图像的 html
<div class="pull-left custom-photo">
<a href="javascript:newWindow('https://www.example.com/cover/6EB90E2A3A54EB14810A178E4A5FF927/');"><img src="https://static.example.com/media/6EB90E2A3A54EB14810A178E4A5FF927/t_cover_6EB90E2A3A54EB14810A178E4A5FF927.jpg" alt="" class="img-responsive"/></a>
</div>
我需要获取
中的图片<a href="javascript:newWindow('HERE');"><img src="https://static.metart.com/media/6EB90E2A3A54EB14810A178E4A5FF927/t_cover_6EB90E2A3A54EB14810A178E4A5FF927.jpg" alt="" class="img-responsive"/></a>
我试过了:
imgSec = soup.find('div',{'class':'pull-left custom-photo'})
for item in imgSec.find_all('a'):
url = item.get('href')
但我无法提取javascript:newWindow 之后的第一个链接
有什么建议吗?
【问题讨论】:
-
发帖前请阅读网站规则。您必须在帖子中包含代码。
-
"javascript:newWindow ..."是普通字符串,因此请使用标准字符串函数,如split()或切片text[start:stop]。
标签: python html beautifulsoup web-crawler