import urllib
import pandas as pd
import requests
import numpy
from bs4 import BeautifulSoup
def get_data(url):
resp = requests.get(url)
html = resp.content.decode("gbk")
soup = BeautifulSoup(html,'html.parser')
hero_list = soup.find_all('img')
heroname,heroimg=[],[]
for heroinfo in hero_list[0:]:
hero = str(heroinfo).split()
heroname=hero[1][5:-1]
heroimg=hero[3][7:-1]
#print(heroimg)
request=urllib.request.urlopen("http://" + heroimg)
#imginfo=requests.get(heroimg)
#print(imginfo.status_code)
path = "F:/python/Test/wzryHero/"+heroname+".jpg"
f=open(path,'wb')
buf=request.read()
f.write(buf)
f.close()
# f.write(img)
#print(hero[3][5:-1])
get_data('https://pvp.qq.com/web201605/herolist.shtml')
网友评论