使用Python爬取王者榮耀英雄全部裝備圖

爬取結果


使用Python爬取王者榮耀英雄全部裝備圖

爬取過程


使用Python爬取王者榮耀英雄全部裝備圖

爬取代碼

爬取的代碼在這裡就直接給大家分享出來,喜歡的朋友,可以關注、收藏、點贊、轉發。

<code>import requests
from bs4 import BeautifulSoup

headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/63.0.3239.26 Safari/537.36 Core/1.63.5958.400 SLBrowser/10.0.3533.400'}


def GetSoup(url):
resp = requests.get(url, headers=headers)
resp.encoding = 'gbk'
soup = BeautifulSoup(resp.text, 'lxml')
return soup

# 裝備
url2 = "https://pvp.qq.com/web201605/item.shtml"
soup = GetSoup(url2)
alldiv2 = soup.find_all('a', href='#none')
for div in alldiv2:
url3 = 'https:' + div.find('img')['src']
title = div.find('img')['alt']
resp2 = requests.get(url3, headers=headers)
print('正在下載%s.jpg.....' % title)
f = open('D:/圖庫/圖/王者榮耀裝備圖/裝備-%s.jpg' % title, 'wb')
f.write(resp2.content)
f.close()/<code>


分享到:


相關文章: