python3 beautifulsoup解析网页下载图片

网友投稿 808 2022-11-08

python3 beautifulsoup解析网页-图片

python3 beautifulsoup解析网页-图片

今天有朋友叫我解析以下img的url,然后-图片,这里我分享一下我的-过程。

import urllib.requestfrom bs4 import BeautifulSoup#获取页面信息def getHtml(url): html = urllib.request.urlopen(url).read() return htmlurl='= BeautifulSoup(html,"html.parser") # 缩进格式for item in bs.find_all("img"): print(item) img_path=item.get('src') if(img_path.startswith(' urllib.request.urlretrieve(img_path, 'img.jpg')

这是演示代码,读者可以根据需要进行修改。

参考文献

[1].Python-URL图片. ​​-图片.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:mac使用juicefs的时候TypeError: a bytes-like object is required, not 'str'
下一篇:mac node-sass 安装错误
相关文章

 发表评论

暂时没有评论,来抢沙发吧~