import requests
import json
def proxies():
ip_proxy = 'https://api.=EG4Qsl=text'
ip = requests.get(ip_proxy).text
print(ip)
proxy = {
'https': ip
}
with open('proxiex.txt', 'w') as f:
f.write(json.dumps(proxy))
from apscheduler.schedulers.blocking import BlockingScheduler
scheduler = BlockingScheduler()
scheduler.add_job(proxies, 'interval', seconds=11, id='proxies')
scheduler.start()
def proxy_id(self):
with open('proxiex.txt', 'r', encoding='utf-8') as f:
data = json.loads(f.read())
return {
'https': data['https']
}
使用
resp = requests.get(url, headers=Upload_data.headers, proxies=self.proxy_id(), timeout=5)