找回密码
 会员注册
查看: 22|回复: 0

一个非常简单的网页刷量脚本(Python)

[复制链接]

2万

主题

0

回帖

6万

积分

超级版主

积分
69864
发表于 2024-9-10 15:26:28 | 显示全部楼层 |阅读模式
一、脚本功能增加网页浏览量,简称刷量二、脚本文件结构ipporxy.txt  #存放代理ipmain.py#主程序proxiesIp.py#代理ip检测user_set.py#刷量调整区域三、具体代码ipporxy.txt116.253.208.239:33080123.56.175.31:3128139.9.64.238:443123.56.175.31:3128139.9.64.238:443main.py#!/usr/bin/envpython'''1.手动输入某个新闻链接,然后模拟人工访问网页2.可定义:N个网页、刷新数量、刷新速度、访问浏览器3.数量要求:[700~100000]'''fromastimportTryimportrequestsimportwarningsimporturllib3frombs4importBeautifulSoupimportos,time,random,datetimeimport_thread,queueimportuser_setasuserfromseleniumimportwebdriverfromselenium.webdriver.chrome.optionsimportOptionsfromrequests.packages.urllib3.exceptionsimportInsecureRequestWarningwarnings.filterwarnings('ignore')requests.packages.urllib3.disable_warnings(InsecureRequestWarning)urllib3.disable_warnings()available_ip=''test_url='https://www.baidu.com'#读取有效ip文件defip_file():available_ips=[]try:withopen('./ipporxy.txt','r',encoding='UTF-8')asf:forlinf.readlines():available_ips.append(l.rstrip('\n'))returnavailable_ipsexceptException:print("Error没有ipporxy.txt文件")exit()defip_random():ips=ip_file()ifips:proxie=random.choice(ips)requests.DEFAULT_RETRIES=5s=requests.session()s.keep_alive=Falseproxies={"http":proxie,"https":proxie}try:res=requests.get(test_url,proxies=proxies,verify=False,timeout=2)exceptException:print('代理ip连接出错,更换ip中...')ip_random()else:ifres.status_code==200:print('ip通道正常:[%s],可以使用....'%proxie)available_ip=proxieselse:print('Error没有可用的代理ip')#设置主功能,传入线程defpv_pool(name,url,count):foriinrange(count):headers=random.choice(user.UserAgent1)chrome_options=Options()webdriver.DesiredCapabilities.CHROME['acceptSslCerts']=Truechrome_options.add_argument('headless')chrome_options.add_argument('--disable-gpu')chrome_options.add_argument('--no-sandbox')chrome_options.add_argument('--user-agent=%s'%headers)try:chrome_options.add_argument('--proxy-server=%s'%available_ip)driver=webdriver.Chrome(options=chrome_options)driver.get(url)#访问页面exceptException:print('Error访问出现错误,更换ip')ip_random()continueelse:time.sleep(random.uniform(user.speed_low,user.speed_high))driver.close()print("第%d次访问网页【%s】"%(i+1,datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S')))print('~~~~{}线程结束时间:{}~~~~~\n'.format(name,datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S')))if__name__=="__main__":#获取有效ip地址ip_random()#开始刷点击量forsiteinuser.webSites:url=site['url']times=int(site['times'])//3print(times)try:#print(url,times)#启动多线程print('※※※※※线程启动时间:{}※※※※\n'.format(datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S')))_thread.start_new_thread(pv_pool,(1,url,times))_thread.start_new_thread(pv_pool,(2,url,times))_thread.start_new_thread(pv_pool,(3,url,times))except:print("Error:无法启动线程")while1:passproxiesIp.pyimporttelnetlibimportrequeststest_url='https://www.baidu.com'#ip检测,存储有效ip地址defip_is_alive(ip_port):ip,port=ip_port[0],ip_port[1]try:tn=telnetlib.Telnet(ip,port=port,timeout=1)except:print('[-]无效ip:{}:{}'.format(ip,port))else:proxies=ip+':'+porttry:res=requests.get(test_url,proxies={"http":proxies,"https":proxies},timeout=1)except:print('[-]无效ip:{}:{}'.format(ip,port))else:ifres.status_code==200:print('[+]有效ip:{}:{}'.format(ip,port))#将有效ip写入文件中withopen('ipporxy.txt','a+')asf:f.write(ip+':'+port+'\n')'运行运行user_set.py#!/usr/bin/envpythonimportproxiesIpimportrequestsfromlxmlimportetree#设置多个需要刷量网址,及其次数,默认值为numnum=30webSites=[{'url':'www.baidu.com','times':num}]#多个网页#webSites=[{'url':'xxx','times':num},{'url':'xxx','times':num}]#设置随机的刷新速度speed_low=2speed_high=3#设置微信浏览器:安卓,iosUserAgent1=[{'User-Agent':'mozilla/5.0(linux;u;android4.1.2;zh-cn;mi-oneplusbuild/jzo54k)applewebkit/534.30(khtml,likegecko)version/4.0mobilesafari/534.30MicroMessenger/5.0.1.352'},{'User-Agent':'mozilla/5.0(iphone;cpuiphoneos5\_1\_1likemacosx)applewebkit/534.46(khtml,likegecko)mobile/9b206MicroMessenger/5.0'},{'User-Agent':'Mozilla/5.0(Linux;Android5.0;SM-N9100Build/LRX21V)>AppleWebKit/537.36(KHTML,likeGecko)Version/4.0>Chrome/37.0.0.0MobileSafari/537.36>MicroMessenger/6.0.2.56\_r958800.520NetType/WIFI'},{'User-Agent':'Mozilla/5.0(iPhone;CPUiPhoneOS7\_1\_2likeMacOSX)>AppleWebKit/537.51.2(KHTML,likeGecko)Mobile/11D257>MicroMessenger/6.0.1NetType/WIFI'},{'User-Agent':'Mozilla/5.0(Linux;U;Android2.3.6;zh-cn;GT-S5660Build/GINGERBREAD)AppleWebKit/533.1(KHTML,likeGecko)Version/4.0MobileSafari/533.1MicroMessenger/4.5.255'},{'User-Agent':'Mozilla/5.0(iPhone;CPUiPhoneOS7_1_2likeMacOSX)AppleWebKit/537.51.2(KHTML,likeGecko)Mobile/11D257MicroMessenger/6.1NetType/WIFI'}]#设置pc浏览器:chrome、safari、火狐等UserAgent2=[{'User-Agent':'Mozilla/5.0(Macintosh;IntelMacOSX10_15_7)AppleWebKit/537.36(KHTML,likeGecko)Chrome/102.0.0.0Safari/537.36'},{'User-Agent':'Mozilla/5.0(WindowsNT6.1;WOW64)Apple\WebKit/537.36(KHTML,likeGecko)Chrome/69.0.3497.92Safari/537.36'},{'User-Agent':'Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/86.0.4240.198Safari/537.36'},{'User-Agent':'Mozilla/5.0(WindowsNT6.1;WOW64;rv:40.0)Gecko/20100101Firefox/40.1'},{'User-Agent':'Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/86.0.4240.198Safari/537.36'},{'user-agent':'Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/78.0.3904.108Safari/537.36'},{'user-agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/70.0.3538.102Safari/537.36Edge/18.18362'},{'user-agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/90.0.4430.93Safari/537.36'}]#测试伪装ip地址,后期设置ip接口获取defturn_symbol(c1):new_c1=c1.replace('\n','').replace('\t','')returnnew_c1#获取免费代理网站ip(ip+空格+port形式)defgetfreeIps():f=open('ipporxy.txt',"r+")f.truncate()foriinrange(1,100):url='http://www.89ip.cn/index_{}.html'.format(i)res=requests.get(url)res.encoding='utf-8'html=etree.HTML(res.text)ipdress=html.xpath('//table[@class="layui-table"]/tbody/tr/td[1]/text()')port=html.xpath('//table[@class="layui-table"]/tbody/tr/td[2]/text()')ipdress=list(map(turn_symbol,ipdress))port=list(map(turn_symbol,port))data=list(zip(ipdress,port))forjinrange(len(data)):#测试并存储有效ipproxiesIp.ip_is_alive([data[j][0],data[j][1]])if__name__=="__main__":#测试可用的ip地址,并进行本地存储getfreeIps()
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2025-1-7 06:46 , Processed in 0.420000 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表