增加blog文章点击量(python)

import requests as req
import threading
from bs4 import BeautifulSoup
import time

blog_url = 'csdn博客地址' #博客所在地址
is_proxy = True #是否开启代理
user = '123456' #用户名
password = '123456' #密码
loop = 3 #循环次数
proxy = {#代理设置
    "http":"http://{__user}:{__password}@10.191.131.43:3128".format(__user=user,__password=password),
    "https":"http://{__user}:{__password}@10.191.131.43:3128".format(__user=user,__password=password)
}
header = {
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'
}

if(is_proxy==False):
    proxy=None

blog_html = req.get(blog_url,proxies=proxy,headers=header).text
blog_html_tree = BeautifulSoup(blog_html,'lxml')
blog_href_list = [item["href"] for item in blog_html_tree.select("div.article-item-box h4 a")]
delay_time = 60

def up_click(href_list,proxy,header,loop_num):
    for href in href_list:
      req_get(href,proxy,header,loop_num)


def req_get(href,proxy,header,loop_num):
    req.get(href,proxies=proxy,headers=header)
    loop_num=loop_num-1
    print(time.time(),href)
    if(loop_num==0):
        return 
    threading.Timer(delay_time,req_get,(href,proxy,header,loop_num)).start()

up_click(blog_href_list,proxy,header,loop)

这里需要注意一点:需要设置延迟发送请求,因为1分钟内对文章页面的点击都是无效的
,因此需要设置 delay = 60 ,并设置threading.Timer定时器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值