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爬取头像网站图片所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)