推荐学习书目
› 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
yezhiye
V2EX  ›  Python

爬虫 DNS 问题

  •  
  •   yezhiye · Oct 30, 2020 · 2298 views
    This topic created in 2198 days ago, the information mentioned may be changed or developed.

    各位大佬,我想问一下: python 的 requests 库的 dns 查询,默认走不走 socks5 ? 想到一个问题,如果机器在北京,代理在广东,就导致 1 个广东的 ip 总是访问北京的服务器,很奇怪吧…… 1.DNS 查询好像是先查询本机的 DNS 记录,这样我是不是每次都得清除本地 DNS 记录,然后通过让 DNS 查询走代理? 2.怎么下载目标网站的证书用于检验?

    google 只找到了不用代理情况下查询 requests 远程服务器 ip 的方法: r = requests.get(url,headers=headers,proxies=proxies,stream=True) print(r.raw._fp.fp.raw._sock.getpeername()) 但是上了代理,就返回本地代理端口,英语不行查不动了……

    不是处女座,单纯是好奇,感谢各位大佬!!!!!!!!!

    8 replies  •  2020-10-31 22:24:32 +08:00
    yezhiye
    yezhiye
    OP
    Oct 30, 2020 via Android
    1
    想爬上了 CDN 的大站…
    yezhiye
    yezhiye
    OP
    Oct 30, 2020 via Android
    2
    第一次发这么长,才发现格式乱了,各位大佬多担待…
    Kobayashi
    Kobayashi
    Oct 30, 2020 via Android❤️1
    3
    pip install requests[socks]
    socks5h://host:port
    yezhiye
    yezhiye
    OP
    Oct 30, 2020 via Android
    4
    @Kobayashi 我知道怎么设置代理,我想在每次换代理 ip 的时候重新查询 dns,让代理 ip 跟上了 cdn 的服务器的 ip 对应上…
    Jirajine
    Jirajine
    Oct 30, 2020 via Android❤️1
    5
    socks 直接传域名就是远端查询了。
    Te11UA
    Te11UA
    Oct 31, 2020❤️1
    6
    就是 socks5h,socks5 加了 h 就是 DNS 也走代理啊
    SingeeKing
    SingeeKing
    Oct 31, 2020❤️1
    7
    In a proxy string, socks5h:// and socks4a:// mean that the hostname is resolved by the SOCKS server. socks5:// and socks4:// mean that the hostname is resolved locally
    yezhiye
    yezhiye
    OP
    Oct 31, 2020 via Android
    8
    @Te11UA
    @SingeeKing 感谢两位大佬
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1921 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 08:33 · PVG 16:33 · LAX 00:33 · JFK 03:33
    ♥ Do have faith in what you're doing.