python项目之 增加博客访问量
为什么要有?
写博客的访问量太低,没动力继续写,需要刷榜增加人气。
当然了,学技术为主,你懂的!
需准备文件
代理的ip地址
写成txt文件,格式
博客的地址
写成txt文件
博客标题,下面是博客地址
http://XXXXXXXX
思路
模拟浏览器登录,为了防止被服务器堵IP,还是用到了代理IP地址。
改进
后续再把浏览器信息扩展就完美了。
源码如下
# coding = utf-8
####################################################
# coding by 刘云飞
####################################################
import requests
import re
import time
import random
from random import choice
ips = []
blog_ads = []
with open('ip.txt', 'r') as f:
lines = f.readlines()
for line in lines:
ip_one = line.strip()
ips.append(ip_one)
with open('blogdizhi.txt', 'r', encoding='utf-8') as f2:
lines = f2.readlines()
line_num = len(lines)
pag = 0
for line in lines:
pag += 1
if pag % 2 == 0:
ads = line.strip()
blog_ads.append(ads)
else:
ads = line.strip()
headers = {
'Host': 'blog.youkuaiyun.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/42.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate',
'Referer': 'http://www.google.com',
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
}
i = 0
j = 0
while i < 548:
blog = random.choice(blog_ads)
ip_i = random.choice(ips)
proxies = {'http': ip_i}
print(blog)
print(proxies)
i += 1
print("now trying " + str(i) + ',failed ' + str(j))
sleep_time = random.randint(5, 23)
print('------>sleep ' + str(sleep_time) + " s")
time.sleep(sleep_time)
session = requests.session()
try:
response = session.get(blog, headers=headers, proxies=proxies)
str_code = response.status_code
print('>>>>>' + str(str_code))
if str_code > 200:
j += 1
except:
print('time out')
j += 1
pass
session.close()