V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
woshichuanqilz
V2EX  ›  Python

爬取亚马逊使用代理的问题

  •  
  •   woshichuanqilz · 2020-07-28 12:10:05 +08:00 · 2825 次点击
    这是一个创建于 1360 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本地 python requests 直接抓这个网址的内容是 ok 的, 我从快代理上买了代理再用 requests 抓就不行, 但是我用 selenium 加上代理是可以看到这个网页的, 于是我先用 selenium 加代理打开网页, 然后把 requests headers(包括 cookies) 复制出来(就是从开发者模式复制出来), 再用 request 还是不行, requests 抓到的页面需要验证, 但是如果不使用代理, 直接用我本机的 ip, requests 使用 selenium + 代理 获取到的 requests header 使用 也是成功的。 请问这样的问题应该如何解决, 为什么 selenium 没有被禁, 但是 request 使用同样的 headers + 代理就不行, 除了 request header 里面的信息, 服务器是什么逻辑判断我的 request 是爬虫的

    https://www.amazon.co.uk/s?k=dress&ref=nb_sb_noss

    第 1 条附言  ·  2020-07-28 14:42:02 +08:00
    使用本地 ip:
    1. selenium 正常
    2. 使用 requests, requests 用本地正常打开浏览器 抓下来的 requests header , 访问正常
    3. 使用 requests, requests 用代理的 selenium 抓下来的 requests header , 访问正常

    使用代理:
    1. selenium 正常
    2. 使用 requests, requests 用本地正常打开浏览器 抓下来的 requests header , 访问 不正常, 只是抓到验证页面
    3. 使用 requests, requests 用代理的 selenium 抓下来的 requests header , 访问 不正常, 只是抓到验证页面
    8 条回复    2020-07-28 17:04:21 +08:00
    ooh
        1
    ooh  
       2020-07-28 12:12:25 +08:00
    代理 IP 直接被识别成代理 IP 去了?
    zh1997
        2
    zh1997  
       2020-07-28 12:25:14 +08:00 via iPhone
    通过代理抓取的内容 和状态码是什么
    gluttony
        3
    gluttony  
       2020-07-28 14:04:25 +08:00
    cookies 或 LocalStorage 里有些值是通过 JavaScript 算的。你用 request 库不支持 eval js,请求时没有带上这些值就被判定为不正常请求了。
    woshichuanqilz
        4
    woshichuanqilz  
    OP
       2020-07-28 14:25:30 +08:00 via Android
    @gluttony 本地 IP 不加代理可以的
    woshichuanqilz
        5
    woshichuanqilz  
    OP
       2020-07-28 14:25:56 +08:00 via Android
    @zh1997 一个验证页面就是填验证码的页面
    woshichuanqilz
        6
    woshichuanqilz  
    OP
       2020-07-28 14:26:11 +08:00 via Android
    @ooh 什么意思
    Te11UA
        7
    Te11UA  
       2020-07-28 15:58:54 +08:00
    代理 IP 大部分都是复用的,被识别出来很正常,你自己的 IP 又没有什么异常行为当然放过你了。做验证码识别可以缓解。
    gluttony
        8
    gluttony  
       2020-07-28 17:04:21 +08:00
    你有没有更换 user-agent ?

    ```bash
    curl 'https://www.amazon.co.uk/s?k=dress&ref=nb_sb_noss' \
    -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246' \
    -H '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' \
    -H 'accept-language: en-US,en;q=0.9' \
    --compressed
    ```
    用普通 ip 地址的话访问正常。把 user-agent 改成 curl 等不正常字符串就返回 301,如果你的 request lib 没有设置 follow redirect 的话就得不到正确的网页内容了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5189 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:21 · PVG 09:21 · LAX 18:21 · JFK 21:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.