‘’照葫芦画瓢‘’CPU天梯图爬取
照葫芦画瓢import requests #加载模块
import bs4
head={}
head['User-Agent']= "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3775.400 QQBrowser/10.6.4209.400"
#head伪装浏览器
res = requests.get("https://cpu.51240.com/",headers=head)
soup = bs4.BeautifulSoup(res.text,"html.parser")
targets = soup.find_all("div",class_="mingcheng") #数据路径
for each in targets:
print(each.b.text,each.a.text) #打印排名和名称
页:
[1]