Python脚本运行缓慢

时间:2019-03-22 22:40:14

标签: python

由于某些原因,此代码运行非常慢

我曾尝试更换代理,但这似乎不是问题所在

from bs4 import BeautifulSoup
import requests

ipLogger = "";#link for logger
agent = "X";
referer = "X";
scrapeHttpsProxies = 0;

print("Botting Link: " + ipLogger);

proxies = open("https.txt", "r");

print("Found " + str(sum(1 for line in open('https.txt')))+ " HTTPS Proxies.");

while True:
    for x in proxies:
        if x != "":
            try:
                headers = {
                    "user-agent": agent,
                    "referer": referer
                };
                proxy = {
                    "https": x.strip()
                }
                req = requests.get(url=ipLogger, headers=headers, proxies=proxy, timeout=5);
                status = req.status_code;
                if status == 404:
                    print("Connection error - Bad Proxy");
                elif status == 403:
                    print("Connection error - Bad Proxy");
                elif status == 200:
                    print("Working request with proxy: " + x.strip());
                else:
                    print("Unknown Status Code:", status);
            except IOError:
                print("Connection error - Bad Proxy");

print("\nFinished sending requests!");

我希望它运行得很快,并且可以快速通过代理,但是实际上它运行起来相对较慢

0 个答案:

没有答案