查了一下 Stack Overflow 问题可能在 ssl 上, 但是改了还是不行。
import asyncio
import requests
import time
import json
import random
import aiohttp
from ori_async import get_proxy
list_url = 'https://www.amazon.co.uk/s?k=dress&ref=nb_sb_noss'
product_url = 'https://www.amazon.co.uk/AUSELILY-Womens-Sleeve-Pleated-Pockets/dp/B082W811L3/ref=sr_1_1_sspa?dchild=1&keywords=dress&qid=1596264150&s=clothing&sr=1-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEzTEpRR0NLRlhQMFFDJmVuY3J5cHRlZElkPUEwMDY5Nzg5MkZTUllZWTM3VFVIQiZlbmNyeXB0ZWRBZElkPUEwOTU0NzQ1MTE0QzhFV0w0SjJOMCZ3aWRnZXROYW1lPXNwX2F0ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU='
baidu_url = 'https://www.baidu.com'
headers = {
"authority": "www.amazon.co.uk",
"method": "GET",
"path": "/s?k=dress&i=clothing&ref=nb_sb_noss",
"scheme": "https",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-US;q=0.7,ja;q=0.6,zh-TW;q=0.5",
"cache-control": "max-age=0",
"cookie": "session-id=258-7467381-0898317; i18n-prefs=GBP; ubid-acbuk=262-6045121-6110346; x-wl-uid=13CgqXYwZCFN3okL9HYQm7Iyt8Md2S5Dj4uA/dwKZrgtM0V8Ii0/OTO/AbtTOSRVzmlpbyCfIvZw=; session-token=\"K1UgAkfjQLKORhX6CN0AXXcRycoGecW5zqC3Nk8y/0rr7ZHQPpm5kzjT0YPAY/M8vVOWYNXoWCDYhSbrXyHP/bnNILWcLd2I+04dfUASNtpMHQkTh2YNffN748Rd9HxMQ6wFjVkDsfhgbm/YgEQ5uy8H+qWM1i9z+8uePKVL1BfVQtQpOEFxLQK+1GRQHBfdt7urN81Bkg0WjHz3pOVR31pILIjf3aM1nhncWG1P/A93yPpUOBTFeMh5/6V4RrddfHGn4uifWdg=\"; session-id-time=2082758401l; csm-hit=tb:3GP38DER2C68WEEPMTK8+s-KCAYBB85E78WBDWP92X7|1595834228498&t:1595834228498&adb:adblk_yes",
"downlink": "9.75",
"ect": "4g",
"rtt": "200",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4181.9 Safari/537.36"
}
url = list_url
# proxies = get_proxy()
async def main():
connector = aiohttp.TCPConnector(ssl=False)
async with aiohttp.ClientSession(connector=connector) as session:
async with session.get(url, headers=data["headers"]) as resp:
print(resp.status)
content = await resp.text()
print(len(content))
start = time.time()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
end = time.time()
print('spend time is {}'.format(end - start))
# response = requests.get(url, headers=headers, proxies=proxies, timeout=8, verify=False)
response = requests.get(url, headers=headers, timeout=8, verify=False)
print("length is {}".format(len(response.text)))
1
locoz 2020-08-02 17:00:29 +08:00
抓包对比,分分钟就能看到问题所在
|
2
woshichuanqilz OP |
3
picone 2020-08-02 22:46:37 +08:00
wireshark 抓包对比下,可能底层做了些奇怪的处理。
|
4
Trim21 2020-08-02 22:51:46 +08:00 via Android
aiohttp 不能设置 proxy 吗…
|
5
gesse 2020-08-02 22:52:24 +08:00
电商网站, 不一样的用户指纹,返回不一样的内容不很正常吗?
|
6
woshichuanqilz OP @gesse 两个方法用的信息基本是一样的 你说的指纹具体指的是什么这个例子能修改吗
|
7
woshichuanqilz OP @Trim21 可以但是这个是是代理的问题吗
|
8
Trim21 2020-08-02 23:16:26 +08:00 via Android
@woshichuanqilz 我是说 fiddler 抓包的问题
|
9
Nigelchiang 2020-08-02 23:27:34 +08:00
楼主你的 cookie 都泄露了,赶紧把亚马逊退出重登一下吧
|
10
levelworm 2020-08-02 23:30:48 +08:00
cookie 建议不要贴出来。
|
11
gesse 2020-08-03 00:01:26 +08:00
|
12
locoz 2020-08-03 11:36:30 +08:00
@woshichuanqilz #2
aiohttp 的请求在抓包工具里不显示大概是因为你根本没有设置让它走代理,在请求的时候带上 proxy 参数就行了。 抓包先看 HTTP 层的各个参数有没有区别,有的话先处理成一模一样的。aiohttp 和 requests 的实现不同,对一些情况的处理并不相同,比如常见容易出问题的情况是 headers 里多了东西或者少了东西,或者是某个有特殊符号之类的 value 被编码成另一种样子之类的。 如果 HTTP 层都统一了但还是有区别的话,就用 wireshark 看看 SSL 层有没有什么区别,比如常见用来做 SSL 指纹的加密套件部分。 |
13
Te11UA 2020-08-05 17:09:05 +08:00
不一样是什么意思,长度不一样还是验证码?
|