【发布时间】:2021-07-03 06:39:04
【问题描述】:
我正在使用漂亮的汤从网站上抓取图像,但是我的代码没有返回在检查网页时可见的图像的完整地址。
for b in soup.select(".thumb_div.clear a"):
imagelink = a["href"].replace("/mushrooms/", "http://www.foragingguide.com/mushrooms/")
print(imagelink)
应该返回:http://static.foragingguide.com/photos/mushrooms/amethyst_deceiver/87.jpg
因为源代码是:
<a href="http://static.foragingguide.com/photos/mushrooms/amethyst_deceiver/87.jpg" rel="lightbox[photos]" title="Amethyst Deceiver (Laccaria amethystina)">
但只是返回 http://static.foragingguide.com/photos/mushrooms/amethyst_deceiver/ 而没有 jpg 文件结尾,这是工作所必需的。
有谁知道这是为什么? 谢谢。
【问题讨论】:
-
为什么需要更换?链接不是绝对的吗?
-
它不返回绝对链接,只是一个相对路径,因此我做了一个替换
标签: python html web web-scraping beautifulsoup