Python 批量刷博客园访问量脚本过程解析
作者:卿先生 发布时间:2023-11-23 21:30:14
标签:python,批量,刷,访问量,脚本
今早无聊。。。7点起来突然想写个刷访问量的。。那就动手吧
仅供测试,不建议刷访问量哦~~
很简单的思路,第一步提取代理ip,第二步模拟访问。
提取HTTP *
网上很多收费的代理和免费的 *
如:
无论哪个网站,我们需要的就是爬取上面的ip和端口号,整理到一起。
具体的网站根据具体的结构爬取 比如上面那个网站,ip和端口在td标签
这里利用bs4爬取即可。贴上脚本
##获取代理ip
def Get_proxy_ip():
print("==========批量提取ip刷博客园访问量 By 卿=========")
print(" Blogs:https://www.cnblogs.com/-qing-/")
print(" Started! ")
global proxy_list
proxy_list = []
url = "https://www.kuaidaili.com/free/inha/"
headers = {
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding":"gzip, deflate, sdch, br",
"Accept-Language":"zh-CN,zh;q=0.8",
"Cache-Control":"max-age=0",
"Connection":"keep-alive",
"Cookie":"channelid=0; sid=1561681200472193; _ga=GA1.2.762166746.1561681203; _gid=GA1.2.971407760.1561681203; _gat=1; Hm_lvt_7ed65b1cc4b810e9fd37959c9bb51b31=1561681203; Hm_lpvt_7ed65b1cc4b810e9fd37959c9bb51b31=1561681203",
"Host":"www.kuaidaili.com",
"Upgrade-Insecure-Requests":"1",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0",
"Referrer Policy":"no-referrer-when-downgrade",
}
for i in range(1,100):
url = url = "https://www.kuaidaili.com/free/inha/"+str(i)
html = requests.get(url = url,headers = headers).content
soup = BeautifulSoup(html,'html.parser')
ip_list = '';
port_list = '';
protocol_list = '';
for ip in soup.find_all('td'):
if "IP" in ip.get('data-title') :
ip_list = ip.get_text()##获取ip
if "PORT" in ip.get('data-title'):
port_list = ip.get_text()##获取port
if ip_list != '' and port_list != '':
proxy = ip_list+":"+port_list
ip_list = '';
port_list = '';
proxy_list.append(proxy)
iv_main()
time.sleep(2)
proxy_list = []
这样就把 提取的ip和端口放到列表里
模拟访问刷博客园文章
这里就很简单了 ,遍历上面那个代理ip的列表,使用requests模块取访问就是了
def iv_main():
proxies = {}
requests.packages.urllib3.disable_warnings()
#proxy_ip = random.choice(proxy_list)
url = 'https://www.cnblogs.com/-qing-/p/11080845.html'
for proxy_ip in proxy_list:
headers2 = {
'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'accept-encoding':'gzip, deflate, sdch, br',
'accept-language':'zh-CN,zh;q=0.8',
'cache-control':'max-age=0',
'cookie':'__gads=ID=8c6fd85d91262bb1:T=1561554219:S=ALNI_MZwz0CMKQJK-L19DrX5DPDtYvp63Q; _gat=1; _ga=GA1.2.359634670.1561535095; _gid=GA1.2.1087331661.1561535095',
'if-modified-since':'Fri, 28 Jun 2019 02:10:23 GMT',
'referer':'https://www.cnblogs.com/',
'upgrade-insecure-requests':'1',
'user-agent':random.choice(user_agent_list),
}
proxies['HTTP'] = proxy_ip
#user_agent = random.choice(user_agent_list)
try:
r = requests.get(url,headers=headers2,proxies=proxies,verify=False) #verify是否验证服务器的SSL证书
print("[*]"+proxy_ip+"访问成功!")
except:
print("[-]"+proxy_ip+"访问失败!")
最好带上随机的ua请求头
user_agent_list = [
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/45.0.2454.85 Safari/537.36 115Browser/6.0.3",
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
"Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0",
"Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
]
优化整合
这里可以稍微优化下,加入队列线程优化(虽然python这个没啥用)
最终代码整合:
# -*- coding:utf-8 -*-
#By 卿
#Blog:https://www.cnblogs.com/-qing-/
import requests
from bs4 import BeautifulSoup
import re
import time
import random
import threading
print("==========批量提取ip刷博客园访问量 By 卿=========")
print(" Blogs:https://www.cnblogs.com/-qing-/")
print(" Started! ")
user_agent_list = [
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/45.0.2454.85 Safari/537.36 115Browser/6.0.3",
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
"Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0",
"Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
]
def iv_main():
proxies = {}
requests.packages.urllib3.disable_warnings()
#proxy_ip = random.choice(proxy_list)
url = 'https://www.cnblogs.com/-qing-/p/11080845.html'
for proxy_ip in proxy_list:
headers2 = {
'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'accept-encoding':'gzip, deflate, sdch, br',
'accept-language':'zh-CN,zh;q=0.8',
'cache-control':'max-age=0',
'cookie':'__gads=ID=8c6fd85d91262bb1:T=1561554219:S=ALNI_MZwz0CMKQJK-L19DrX5DPDtYvp63Q; _gat=1; _ga=GA1.2.359634670.1561535095; _gid=GA1.2.1087331661.1561535095',
'if-modified-since':'Fri, 28 Jun 2019 02:10:23 GMT',
'referer':'https://www.cnblogs.com/',
'upgrade-insecure-requests':'1',
'user-agent':random.choice(user_agent_list),
}
proxies['HTTP'] = proxy_ip
#user_agent = random.choice(user_agent_list)
try:
r = requests.get(url,headers=headers2,proxies=proxies,verify=False) #verify是否验证服务器的SSL证书
print("[*]"+proxy_ip+"访问成功!")
except:
print("[-]"+proxy_ip+"访问失败!")
##获取代理ip
def Get_proxy_ip():
global proxy_list
proxy_list = []
url = "https://www.kuaidaili.com/free/inha/"
headers = {
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding":"gzip, deflate, sdch, br",
"Accept-Language":"zh-CN,zh;q=0.8",
"Cache-Control":"max-age=0",
"Connection":"keep-alive",
"Cookie":"channelid=0; sid=1561681200472193; _ga=GA1.2.762166746.1561681203; _gid=GA1.2.971407760.1561681203; _gat=1; Hm_lvt_7ed65b1cc4b810e9fd37959c9bb51b31=1561681203; Hm_lpvt_7ed65b1cc4b810e9fd37959c9bb51b31=1561681203",
"Host":"www.kuaidaili.com",
"Upgrade-Insecure-Requests":"1",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0",
"Referrer Policy":"no-referrer-when-downgrade",
}
for i in range(1,100):
url = url = "https://www.kuaidaili.com/free/inha/"+str(i)
html = requests.get(url = url,headers = headers).content
soup = BeautifulSoup(html,'html.parser')
ip_list = '';
port_list = '';
protocol_list = '';
for ip in soup.find_all('td'):
if "IP" in ip.get('data-title') :
ip_list = ip.get_text()##获取ip
if "PORT" in ip.get('data-title'):
port_list = ip.get_text()##获取port
if ip_list != '' and port_list != '':
proxy = ip_list+":"+port_list
ip_list = '';
port_list = '';
proxy_list.append(proxy)
iv_main()
time.sleep(2)
proxy_list = []
th=[]
th_num=10
for x in range(th_num):
t=threading.Thread(target=Get_proxy_ip)
th.append(t)
for x in range(th_num):
th[x].start()
for x in range(th_num):
th[x].join()
结果
来源:https://www.cnblogs.com/-qing-/p/11101414.html
0
投稿
猜你喜欢
- 原来工作中曾经碰到过UL列表里一些异常的表现,加上昨天看到了http://bbs.blueidea.com/thread-2984871-1
- 本文实例讲述了php替换字符串中间字符为省略号的方法。分享给大家供大家参考。具体分析如下:对于一个长字符串,如果你只希望用户看到头尾的部分内
- 本文实例讲述了python实现数值积分的Simpson方法。分享给大家供大家参考。具体如下:#coding = utf-8#simpson
- 现在的离线浏览器很多,可是多数都是共享软件,或是英文软件,这给我们的操作带来了很大的不便。其实微软的网页制作工具FrontPage XP有一
- 使用Northwind 数据库首先查询Employees表查询结果:city列里面只有5个城市使用ROW_NUMBER() OVER(PAR
- 从 Google 的一个细节说起:整个虚线框都是“Next”的可点击区域。看似不经意,却直接提升了细节的可用性。其它页码也巧妙地和上面的字母
- 使用picasa的时候,注意到它首先是显示模糊的图片,然后图片突然变得清晰,这样做有一定的好处——picasa的图片翻页是用javascri
- Mysql数据库是一个多用户,多线程的关系型数据库,是一个客户机/服务器结构的应用程序。它是对个人用户和商业用户是免费的.Mysql数据库具
- phpinfo函数phpinfo函数 PHP中提供了PHPInfo()函数,该函数返回 PHP 的所有信息,包括了 PHP 的编译选项及扩充
- if•Go里面if条件判断语句中不需要括号,条件判断语句里面允许声明一个变量,任何在这里声明的变量都可以在所有的条件分支中使用。if x :
- 前言在启动 Django 项目时,Django 默认监听的端口号为 8000,设置的默认 IP 地址为 127.0.0.1 。如果需要修改默
- 用ASP判断一个字符串中只包含字母和数字要怎么做啊? for s=1 to len(trim(use
- ASP中的全角和半角转化函数,使用方法,传入要转换的字符给str即可,flag设置要转换的类型。<% Function&n
- [sql] -- ===================【创建存储过程】===================== USE [Message
- 在本文上两篇中,我们学习了脚本语言 VBScript 的变量、函数、过程和条件语句,本篇将继续给大家介绍 VBScipt 的循环语句,并对脚
- 本文实例讲述了Python二叉树的镜像转换实现方法。分享给大家供大家参考,具体如下:问题描述操作给定的二叉树,将其变换为源二叉树的镜像。思路
- 使用 NetBox 可以方便的将 asp 应用编译成为独立运行的执行程序,完全摆脱 iis 的束缚,在几乎所有的 Windows 版本上面直
- Oracle DECODE函数功能很强,下面就为您详细介绍Oracle DECODE函数的用法,希望可以让您对Oracle DECODE函数
- 阅读上一篇教程:WEB2.0网页制作标准教程(8)CSS布局入门接下来开始要真正设计布局了。和传统的方法一样,你首先要在脑海里有大致的轮廓构
- 这个类可以用来搜索在给定的文本目录中的文件。 它可以给定目录遍历递归查找某些文件扩展名的文件。 并打开找到的文件,并检查他们是否包含搜索词语