【问题标题】:Python scraping (Image)Python 抓取(图片)
【发布时间】: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


【解决方案1】:

这是普通字符串,所以请使用标准字符串函数 - 即。切片text[22:-3]

text = "javascript:newWindow('https://www.example.com/cover/6EB90E2A3A54EB14810A178E4A5FF927/');" 
print text[22:-3]

https://www.example.com/cover/6EB90E2A3A54EB14810A178E4A5FF927/

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-05-22
  • 2021-01-27
  • 1970-01-01
  • 2017-08-11
  • 2011-02-23
  • 1970-01-01
  • 2013-11-08
  • 1970-01-01
相关资源
最近更新 更多