我被困在使用Python进行网页抓取。基本上,它在下面的请求中给出了htpilla的响应。在
POST https://www.hpe.com/h20195/v2/Library.aspx/LoadMore
Content-Type: application/json
{"sort": "csdisplayorder", "hdnOffset": "1", "uniqueRequestId": "d6da6a30bdeb4d77b0e607a6b688de1e", "test": "", "titleSearch": "false", "facets": "wildcatsearchcategory#HPE,cshierarchycategory#No,csdocumenttype#41,csproducttype#18964"}
-- response --
200 OK
Cache-Control: private, max-age=0
Content-Length: 13701
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 28 May 2016 04:12:57 GMT
Connection: keep-alive
Python2.7.1中使用请求的完全相同的操作失败,并出现错误。以下是代码片段:
^{pr2}$以下是我得到的错误:
{"Message":"Value cannot be null.\r\nParameter name: source","StackTrace":" at
System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value, I
EqualityComparer`1 comparer)\r\n
更多信息: 我要查找的Post请求被触发:
Clicking on the "Load more" grey button at the end of the page
我从浏览器操作捕获请求头和响应的确切集合,并尝试在Postman、Python代码和HttpRequester(Mozilla)中模拟这些内容。在
它用Postman和Python标记相同的错误(上面提到过),但是在HttpRequester中没有设置头。在
有人能想出一个解释吗?在
如果邮递员和},它们在这里丢失了。在
requests
都收到了错误,那么上下文就比HttpRequester
显示的内容要多。我希望几乎总是设置一些头,包括User-Agent
和{常见的疑点是cookies(在早期的请求中查找
Set-Cookie
头,通过使用requests.Session()
对象来保存这些头)、User-Agent
头和可能是Referrer
头,但是要查找其他头,例如以Accept
开头的任何头。在例如,让
HttpRequester
post到http://httpbin.org/post
,并检查返回的JSON,它告诉您发送了什么头。这不包括cookies(那些是特定于域的),但是其他任何东西都可能是服务器要查找的内容。如果cookies没有帮助,请逐个尝试这样的标题。在相关问题 更多 >
编程相关推荐