今天跟朋友談起追星給偶像刷視頻點擊率的問題,就想到能不能用python來解決這個問題,試了一下,視頻的點擊率還是不太好整,勉勉強強用python3實現了給CSDN刷點擊率的問題。
因爲一直用一個IP刷的話,很快就會被封號,這裏找到一個代理IP的網站,https://www.xicidaili.com/,可以試着用裏面的代理IP來刷,不過還是要注意最好休眠時間加大一點。
- 附上代碼
from bs4 import BeautifulSoup
import urllib.request
import socket
import time
import random
User_Agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0'
header = {}
header['User-Agent'] = User_Agent
# 代理IP網址
url = 'https://www.xicidaili.com/wt/1'
req = urllib.request.Request(url, headers=header)
res = urllib.request.urlopen(req).read()
soup = BeautifulSoup(res)
ips = soup.findAll('tr')
f = open("proxy", "w")
# 獲取代理IP
for x in range(1, len(ips)):
ip = ips[x]
tds = ip.findAll("td")
ip_temp = tds[1].contents[0] + "," + tds[2].contents[0] + "\n"
print(tds[1].contents[0] + "\t" + tds[2].contents[0])
f.write(ip_temp)
socket.setdefaulttimeout(3)
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',
]
f = open("proxy")
lines = f.readlines()
proxys = []
for i in range(0, len(lines)):
ip = lines[i].strip().split(",")
proxy_host = "http://" + ip[0] + ":" + ip[1]
print("http://" + ip[0] + ":" + ip[1])
proxy_temp = {"http": proxy_host}
proxys.append(proxy_temp)
# 要刷點擊率的博客
urls = {"https://blog.csdn.net/qq_41725214/article/details/104629344",
"https://blog.csdn.net/qq_41725214/article/details/104501934",
"https://blog.csdn.net/qq_41725214/article/details/104244905"
}
j = 1
for i in range(100):
for proxy in proxys:
for url in urls:
try:
user_agent = random.choice(user_agent_list)
proxy_support = urllib.request.ProxyHandler(proxy)
opener = urllib.request.build_opener(proxy_support, urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
req = urllib.request.Request(url)
c = urllib.request.urlopen(req)
print("sucessful", j)
j += 1
time.sleep(5)
except Exception as e:
print(proxy)
print(e)
continue
刷點擊量的行爲還是可恥的,提高自己文章質量纔是關鍵,畢竟寫博客也是爲了提升自己,避免通次錯誤。像我這麼低的閱讀量都不在乎,why do you care?