python小课——零基础入门——学习笔记

【python】获取王者荣耀所有英雄的头像

2020-04-29  本文已影响0人  白玉寒天

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')

上一篇 下一篇

猜你喜欢

热点阅读