1
我在Python中使用Mechanize来执行一些网页抓取。大多数网站都可以正常工作,但某个特定页面不会返回任何内容或响应。机械化响应不返回内容
我的设置是
self._browser = mechanize.Browser()
self._browser.set_handle_refresh(True)
self._browser.set_debug_responses(True)
self._browser.set_debug_redirects(True)
self._browser.set_debug_http(True)
和执行的代码是:
response = self._browser.open(url)
这是调试输出:
add_cookie_header
Checking xyz.com for cookies to return
- checking cookie path=/
- checking cookie <Cookie ASP.NET_SessionId=j3pg0wnavh3yjseyj1v3mr45 for xyz.com/>
it's a match
send: 'GET /page.aspx?leagueID=39 HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: xyz.com\r\nCookie: ASP.NET_SessionId=aapg9wnavh3yqyrtg1v3ar45\r\nConnection: close\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Tue, 07 Feb 2012 19:04:37 GMT
header: Pragma: no-cache
header: Expires: -1
header: Connection: close
header: Cache-Control: no-cache
header: Content-Length: 0
extract_cookies: Date: Tue, 07 Feb 2012 19:04:37 GMT
Pragma: no-cache
Expires: -1
Connection: close
Cache-Control: no-cache
Content-Length: 0
我一直有和没有重定向尝试徒劳无功。有任何想法吗?
我可能会添加页面在浏览器中正常工作。
调试代理(如fiddler或charles)比wireshark的工作要好得多。 – pguardiario 2012-02-08 02:40:13
@pguardiario感谢您的评论。我从来没有使用过它们,但看起来它们也可以有用(即使它们不是开源的)。 – jcollado 2012-02-08 07:46:01
我在Chrome中启用了开发者会话,似乎可以帮助我解决问题。谢谢 – 2012-02-08 10:28:51