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
yezhiye
V2EX  ›  Python

爬虫 DNS 问题

  •  
  •   yezhiye · 2020-10-30 19:54:46 +08:00 · 956 次点击
    这是一个创建于 1266 天前的主题,其中的信息可能已经有所发展或是发生改变。

    各位大佬,我想问一下: 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 条回复    2020-10-31 22:24:32 +08:00
    yezhiye
        1
    yezhiye  
    OP
       2020-10-30 19:57:42 +08:00 via Android
    想爬上了 CDN 的大站…
    yezhiye
        2
    yezhiye  
    OP
       2020-10-30 20:23:23 +08:00 via Android
    第一次发这么长,才发现格式乱了,各位大佬多担待…
    Kobayashi
        3
    Kobayashi  
       2020-10-30 20:38:09 +08:00 via Android   ❤️ 1
    pip install requests[socks]
    socks5h://host:port
    yezhiye
        4
    yezhiye  
    OP
       2020-10-30 21:03:09 +08:00 via Android
    @Kobayashi 我知道怎么设置代理,我想在每次换代理 ip 的时候重新查询 dns,让代理 ip 跟上了 cdn 的服务器的 ip 对应上…
    Jirajine
        5
    Jirajine  
       2020-10-30 21:23:59 +08:00 via Android   ❤️ 1
    socks 直接传域名就是远端查询了。
    Te11UA
        6
    Te11UA  
       2020-10-31 11:11:27 +08:00   ❤️ 1
    就是 socks5h,socks5 加了 h 就是 DNS 也走代理啊
    SingeeKing
        7
    SingeeKing  
       2020-10-31 15:04:54 +08:00   ❤️ 1
    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
        8
    yezhiye  
    OP
       2020-10-31 22:24:32 +08:00 via Android
    @Te11UA
    @SingeeKing 感谢两位大佬
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1561 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:03 · PVG 01:03 · LAX 10:03 · JFK 13:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.