用python爬取数据并展示

用python爬取数据并展示,第1张



  
    
  
  
    
    
    
    
    
  


import requests
from bs4 import BeautifulSoup
import json

# https://blog.csdn.net/qq_43194257/article/details/87786316  这个文章还可以参考
url = "https://blog.csdn.net/liulang68?spm=1011.2415.3001.5343"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36'}
res = requests.get(url, headers=headers)
content = res.text
soup = BeautifulSoup(content, "lxml")
allCount = soup.select(".user-profile-statistics-num")
# 访问量
fangwenCount = allCount[0].string
# 粉丝数
fensiNum = allCount[1].string
# 排名
paiming = allCount[2].string
# 关注数目
guanzhu = allCount[3].string
authorInfomation = {}
authorInfomation["fangwenCount"]=fangwenCount
authorInfomation["fensiNum"]=fensiNum
authorInfomation["paiming"]=paiming
authorInfomation["guanzhu"]=guanzhu
print(authorInfomation)
json.dump(authorInfomation,open('authorInfomation.json','w'))

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/577942.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)

保存