Python爬取头像网站图片

Python爬取头像网站图片,第1张

概述importurllib.requestfromurllibimportrequestfrombs4importBeautifulSoupx=1url='https://www.woyaogexing.comouxiang/fengjing/'defhiking(url):head={'User-Agent':'Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit
import urllib.requestfrom urllib import requestfrom bs4 import BeautifulSoupx=1url = 'https://www.woyaogexing.com/touxiang/fengjing/'def hiking(url):    head = {'User-Agent': 'Mozilla/5.0 (windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'}    req = request.Request(url,headers=head)    page = urllib.request.urlopen(req)    contents = page.read()    soup = BeautifulSoup(contents,'HTML.parser')    my_picture = soup.find_all('img')    for picture in my_picture:        link = picture.get('src')        a = 'https:'        aa = a + link    #拼接出完整链接        print(aa)        global x        urllib.request.urlretrIEve(aa, 'allimage\%s.jpeg' % x)        print("正在下载第%s张图片" % x)        x += 1for page in range(1,3):              #https://www.woyaogexing.com/touxiang/fengjing/index_2.HTML    page+=1    url = 'https://www.woyaogexing.com/touxiang/fengjing/index_%s.HTML'%page    hiking(url)


总结

以上是内存溢出为你收集整理的Python爬取头像网站图片全部内容,希望文章能够帮你解决Python爬取头像网站图片所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1189066.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存