
1 yangg 2014 年 2 月 24 日 d = pyq(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20140129 Firefox/24.0'}) |
2 yakczh OP @yangg GET / HTTP/1.1 Accept-Encoding: identity Host: localhost:8080 Connection: close User-Agent: Python-urllib/3.2 |
3 pandada8 2014 年 2 月 24 日 为什么不用Requests? |
4 yangg 2014 年 2 月 24 日 print pq('http://ifconfig.me/ua', headers={'user-agent': 'Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20140129 Firefox/24.0'}) 没啥问题 |
5 yakczh OP @yangg 那说明你安装了requests 我安装了requeust以后,再请求就显示正确的ua, pip uninstall requests 以后,再请求又显示 User-Agent: Python-urllib/3.2 ,好象pyq是自动选择的,真是奇怪 |
6 yakczh OP http://pythonhosted.org/pyquery/scrap.html By default it use python’s urllib. If requests is installed then it will use it. This allow you to use most of requests parameters 但是按照缺省的urllib传headers没传进去 |