import requests from bs4 import BeautifulSoup url="https://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gb18030&word=4k%B3%AC%C7%E5%B1%DA%D6%BD&fr=ala&ala=1&alatpl=normal&pos=0&dyTabStr=MCwzLDEsMiw0LDYsNSw4LDcsOQ%3D%3D" page=requests.get(url) page.encoding="gbk" m=page.text b=BeautifulSoup(m,"html.parser") imgs=b.find_all("img") i=1 for img in imgs: k=img["src"] e=f"https://pic.netbian.com/{k}" m=requests.get(e).content with open('E:/img/%s.jpg' %i,"wb") as f: f.write(m) print(f"第{i}个已下载好了") i=i+1
爬取网页图片
最新推荐文章于 2024-11-14 08:46:29 发布