当前位置:网站首页>我的爬虫笔记(七) 通过爬虫实现blog访问量+1
我的爬虫笔记(七) 通过爬虫实现blog访问量+1
2022-07-27 00:19:00 【睡醒继续做梦】
无聊看视频又刷到 别人下载图片的教程 觉得还挺简单 于是有了这篇
虽然 他们都是爬取图片 突然想到是否可以刷下 自己博客的浏览量
给定博客主页 依次进入博客地址 以实现刷取浏览量的效果
理论存在 实践开始
import requests
from bs4 import BeautifulSoup
import time
#替换头部信息(网上找的) 不然进不去
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}
count = 1
url = "https://blog.csdn.net/qq_53950686"#以自己的博客主页为例
respon = requests.get(url,headers=headers)
respon.encoding = 'utf-8'
print(respon.status_code)
#这里应该是把网址转成代码吧
code = BeautifulSoup(respon.text,"html.parser")
#字面意思 标题
print(code.title)
#↓寻找<div class="mainContent"></div>中的a标签
#↓print(code.find("div",class_="mainContent"))取消注释 看一下就会理解
html = code.find("div",class_="mainContent").find_all("a")
#print(html)#取消注释 看一下就会理解
while(1):
for a in html:
blog_url = a.get('href')#博客地址在href中
#print(blog_url)
#下面的就是模拟点击进去
resp = requests.get(blog_url,headers=headers)
resp.encoding = 'utf-8'
code_blog = BeautifulSoup(resp.text,"html.parser")
print(code_blog.title)
print('成功' + str(count) + '次')
count+=1
time.sleep(5)#太快会被制裁
已知的问题
①手动点击进去网址后面会有(?spm=) 百度了一下 叫做埋点 大概是 网页会记录下来源 不清楚有没有危险
②没有加入异常解决办法
③访问量+1好像也只有好看一点 没啥大的卵用 展现量应该才是 具体不知道
也是一不小心 又get一点爬虫知识 又可以水一篇
爬虫小白 如有错误请指正
边栏推荐
猜你喜欢

Blog competition dare to try BAC for beginners

MySQL master-slave database configuration based on docker for Ubuntu

iNFTnews | GGAC联合中国航天ASES 独家出品《中国2065典藏版》

基于GoLang实现API短信网关

Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩

Plato Farm通过LaaS协议Elephant Swap,为社区用户带来全新体验

Static keyword

Web3.0 world knowledge system sharing - what is Web3.0

数据资产管理的概念

static关键字
随机推荐
[NISACTF 2022]上
Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
"Software testing" packaging resume directly improves the pass rate from these points
Arduino UNO +74HC164流水灯示例
[Ryu] common problems and solutions in installing Ryu
Cloud development sleeping alarm clock wechat applet source code
Talk about connection pools and threads
Play a parallel multithreaded mcu-mc3172
[redis] five common data types
快速排序(Quick sort)
What did kubedmin do?
素因子分解--C(gcc)--PTA
C语言程序的编译上
Cuteone: a onedrive multi network disk mounting program / with member / synchronization and other functions
CS224W fall 课程 ---- 1.1 why Graphs ?
白盒测试案例设计(我爷爷都能看懂)
【Redis】五种常用的数据类型
com.fasterxml.jackson.databind.exc.InvalidDefinitionException
Why do people like to rank things
【RYU】安装RYU常见问题及解决办法