Yeah-Kun / python

This is my learn python space.
Apache License 2.0
45 stars 140 forks source link

WeChat voting #3

Open wxr521314 opened 4 years ago

wxr521314 commented 4 years ago

Hi Yeah-Kun: Thank you for the WeChat voting script code. I don't understand how “D:\code\python\new\Brush ticket\IP.txt” got it, do I need to write it by myself?

Yeah-Kun commented 4 years ago

Hi Yeah-Kun: Thank you for the WeChat voting script code. I don't understand how “D:\code\python\new\Brush ticket\IP.txt” got it, do I need to write it by myself?

Yes, you should find the proxy IP and fill it.

For example, You can find the proxy IP in https://www.kuaidaili.com/free or http://www.xiladaili.com/

wxr521314 commented 4 years ago

您好: 感谢你的回信。 我按照你的代码进行了修改。头信息是按照我自己改的。您程序中有个22是自己投票的序号吗,我的是20。 import requests import json import time import re

请求头信息

headers = { 'Accept': '/', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9"', 'Connection': 'keep-alive', 'Content-Length': '1561', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Host': 'mp.weixin.qq.com', 'Origin': 'https://mp.weixin.qq.com', 'Referer': 'https://mp.weixin.qq.com/s/_qDtsnuyYszjNnNxS7eKsA', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3756.400 QQBrowser/10.5.4043.400', 'X-Requested-With': 'XMLHttpRequest' }

post表单网址

url = "https://mp.weixin.qq.com/mp/appmsgreport?action=page_time_5s&__biz=MzI4MzE0NDMyNQ==&uin=&key=&pass_ticket=&wxtoken=777&devicetype=&clientversion=&__biz=MzI4MzE0NDMyNQ%3D%3D&appmsg_token=&x5=0&f=json" params = {'ids': ['20','20','20']} ???

def WriteIPadress(): all_url = [] # 存储IP地址的容器

代理IP的网址

url = "https://www.kuaidaili.com/free"
r = requests.get(url=url)
all_url = re.findall("\d+\.\d+\.\d+\.\d+\:\d+", r.text)
with open("C:\\Users\\User\\PycharmProjects\\IP.txt", 'w') as f:
    for i in all_url:
        f.write(i)
        f.write('\n')
return all_url

计数器

count = 0 while count < 4000: all_url = WriteIPadress() for i in all_url: proxies = {"http": i} try: r = requests.post(url=url, data=params, headers=headers, proxies=proxies, timeout=10) if(r.json()['flag'] == True): count += 1 print("成功投票%d次!" % (count)) print(r.json()) except Exception as reason: print("错误原因是:", reason)

C:\Users\User\PycharmProjects\IP.txt是应该这么写吗? 0539ade14cf9fdc0b754bfa0ddb88aa

我运行后的结果显示 Traceback (most recent call last): File "D:\Users\User\Anaconda3\envs\tp\lib\site-packages\requests\adapters.py", line 449, in send timeout=timeout File "D:\Users\User\Anaconda3\envs\tp\lib\site-packages\urllib3\connectionpool.py", line 725, in urlopen method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File "D:\Users\User\Anaconda3\envs\tp\lib\site-packages\urllib3\util\retry.py", line 439, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.kuaidaili.com', port=443): Max retries exceeded with url: /free (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001F090CCB6D8>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。',))

During handling of the above exception, another exception occurred:

我该如何解决呢?希望你能帮助我解决这个问题。谢谢。