Python3爬虫增加点击量(慎用)

今天跟朋友谈起追星给偶像刷视频点击率的问题,就想到能不能用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?

你可能感兴趣的:(python)