python爬虫


1523 浏览 5 years, 6 months

1 工具

版权声明: 转载请注明出处 http://www.codingsoho.com/

Fiddler

Python默认不用代理,所以fiddler不能截取它的包。如果想用用fiddler来分析Python的网络访问,需要在Python编程里面设置代理

Python does not use proxy by default, so fiddler cannot intercept its network traffic. You may need to change the Python program a little. Here is another thread on how to see proxy for Python programs.

Fiddler基本原理

Fiddler启动后将自己变成一个代理服务器,这个代理服务器默认监听127.0.0.1:8888.然后打开IE的时候,IE浏览器会以127.0.0.1:8888做为自己默认的http代理设置,见下图:

Filter 过滤

方法1:

  1. 切换到右侧的Filter选项卡
  2. 勾选Use Filter
  3. 选择被监控的地址,注意:这个地方输入的域名要跟左边显示的Host列的一致
    “No Host Filter”不设置hosts过滤
    “Hide The Following Hosts”隐藏过滤到的域名
    “Show Only The Following Hosts”只显示过滤到的域名
    “Flag The Following Hosts”标记过滤到的域名
  4. 输入需要过滤的域名,多个域名使用”;“分号分割。fiddler默认会检查http头中设置的host,强制显示http地址中的域名。
  5. 运行“Run Filter Now”即可执行过滤

方法2
根据需要找到request headers或者response headers区域

  1. 勾选“Set request header”
  2. 设置host

参考:

HTTPS & Tunnel To 443

【Tools】->【Fiddler Options】->【HTTPS】
【Rules】-【Hide CONNECTIONs】

常见问题

[Fiddler] The connection to the upstream proxy/gateway failed. Closing Fiddler, changing your system proxy settings, and restarting Fiddler may help. System.Exception Upstream Gateway refused requested CONNECT. 407

打开Fiddler之后,默认的IE代理会被改掉,之前我用的是“Use automatic configuration script”

Fiddler运行后变成下面的代理设置

解决方案如下
【Tools】-> 【Telerik Fiddler Options】,选中Gateway属性页 ,可以选择默认的“Use System Proxy”或者“Manual Proxy Configuration”来设置代理
有些网站设了之后还是不行,比如Oracle

参考文档