2025-12-25 upload
This commit is contained in:
62
参考代码/ai_keyword_crawl/demo_python.py
Normal file
62
参考代码/ai_keyword_crawl/demo_python.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import requests
|
||||
import time
|
||||
import os
|
||||
|
||||
# 禁用系统代理环境变量
|
||||
os.environ['NO_PROXY'] = '*'
|
||||
os.environ['no_proxy'] = '*'
|
||||
if 'HTTP_PROXY' in os.environ:
|
||||
del os.environ['HTTP_PROXY']
|
||||
if 'HTTPS_PROXY' in os.environ:
|
||||
del os.environ['HTTPS_PROXY']
|
||||
if 'http_proxy' in os.environ:
|
||||
del os.environ['http_proxy']
|
||||
if 'https_proxy' in os.environ:
|
||||
del os.environ['https_proxy']
|
||||
if __name__ == '__main__':
|
||||
# 客户ip提取链接,每次提取1个,提取链接可以换成自己购买的
|
||||
#url = 'http://api.tianqiip.com/getip?secret=ew9mj7j3yplbk3xb&num=1&type=txt&port=1&time=3&mr=1&sign=5451e454a54b9f1f06222606c418e12f'
|
||||
url = 'http://api.tianqiip.com/getip?secret=6o09i8io&num=1&type=txt&port=1&mr=1&sign=5451e454a54b9f1f06222606c418e12f'
|
||||
# 访问的目标地址
|
||||
targeturl = 'https://yunqueai.net/?rwl'
|
||||
# 关键修复:获取代理IP时不使用本地代理
|
||||
response = requests.get(url, proxies={})
|
||||
content = response.content.decode("utf-8").strip()
|
||||
# 只取第一个IP(如果返回多个)
|
||||
content = content.split('\n')[0].strip()
|
||||
print('提取IP:' + content)
|
||||
nowtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||
print('提取IP时间:' + nowtime)
|
||||
sj = content.strip().split(":", 1)
|
||||
sj1 = sj[0]
|
||||
print("IP:", sj1)
|
||||
sj2 = sj[1]
|
||||
print("端口:", sj2)
|
||||
try:
|
||||
#proxyMeta = "http://nfd0p2:bHQAp5iW@%(host)s:%(port)s" % { # 账密验证,需要购买的代理套餐开通才可使用账密验证,此种情况无需加白名单
|
||||
proxyMeta = "http://%(host)s:%(port)s" % {#白名单验证
|
||||
"host": sj1,
|
||||
"port": sj2,
|
||||
}
|
||||
print("代理1:", proxyMeta)
|
||||
proxysdata = {
|
||||
'http': proxyMeta,
|
||||
'https': proxyMeta
|
||||
}
|
||||
print("代理2:", proxysdata)
|
||||
headers = {
|
||||
"user-agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.'
|
||||
}
|
||||
start = int(round(time.time() * 1000))
|
||||
resp = requests.get(targeturl, proxies=proxysdata, headers=headers, timeout=20)
|
||||
costTime = int(round(time.time() * 1000)) - start
|
||||
print("耗时:" + str(costTime) + "ms")
|
||||
print("返回:",resp.text)
|
||||
s = requests.session()
|
||||
s.keep_alive = False
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user