1. 程式人生 > 遊戲 >《侏羅紀世界:進化2》開局不樂觀 Frontier降低收入預期

《侏羅紀世界:進化2》開局不樂觀 Frontier降低收入預期

爬取安逸花https://vayh.msxf.com/時出現這種錯誤,總結如下:

1.https連線太多沒有關閉導致的433,解決方法:

import requests
requests.adapters.DEFAULT_RETRIES = 5 # 增加重連次數
s = requests.session()
s.keep_alive = False # 關閉多餘連線
s.get(url) # 你需要的網址

2.訪問次數頻繁,被禁止訪問,解決方法:使用代理

import requests
s = requests.session()
url = "https://vayh.msxf.com/"
s.proxies 
= {"https": "47.100.104.247:8080", "http": "36.248.10.47:8080", } s.headers = header s.get(url)

查詢代理的網址:http://ip.zdaye.com/shanghai_ip.html#Free
使用代理時需注意:
1.代理分為http和https兩種,不能用混,如果把http的代理用作https也是會報上面的錯誤;
2.上面的代理以字典格式傳入,例如上面的例子,可以是“47.100.104.247:8080”這種格式,也可以是“https://47.100.104.247:8080”這種格式
3.如果代理不可用一樣會報上面的錯誤。
以下方法判斷代理是否可用:

import requests
s = requests.session()
s.keep_alive = False
url = "https://vayh.msxf.com/loan/replacevToken?"
headers = {
            'Host': 'vayh.msxf.com',
            'X-Requested-With': 'XMLHttpRequest',
            'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 QBCore/4.0.1301.400 QQBrowser/9.0.2524.400 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2875.116 Safari/537.36 NetType/WIFI MicroMessenger/7.0.5 WindowsWechat
", 'Cookie': cookie, } params = { 'mobile': phone, 'password': '140e0d2deeb6d6b1b803087c03821448c95f3be61ffd27c89f6c391a3288a838', 'saMobile': '', 'smsCode': '', 'channel': 'MS_WeChat_AYH', } url += urlencode(params) response = s.get(url, headers=headers, proxies=proxies, verify=False,timeout=10) print(response.status_code)

如果代理可用則正常訪問,返回code==200說明問題已解決

轉自:https://www.cnblogs.com/gqv2009/p/13215182.html