爬虫代码
import requests
import threading
timeout = 300
lock = threading.Lock()
# 请求头用自己的
headers = {
'': ''
}
class MyProxy:
def __init__(self, proxy_api='', proxy_server='', max_use=5000, try_count=5):
if not (proxy_api or proxy_server):
raise TypeError('Proxy_api and proxy_server cannot be empty at the same time.')
self.proxies = None if not proxy_server else {
'http': proxy_server,
'https': proxy_server
}
# 代理API
self.proxy_api = proxy_api
# 代理 IP 最大使用次数
self.max_use = max_use
# 测试代理 IP 次数,超过次数即认为代理 IP 不可用
self.try_count = try_count
# 是否爬虫请求出错,如果出错,直接更换 IP
self.