MySpider試圖描述加載更多操作點擊,導致網頁上的更多項加載更新。這一直持續到沒有更多需要加載。Scrapy:POST請求返回JSON響應(200 OK),但數據不完整
yield FormRequest(url,headers=header,formdata={'entity_id': '70431','profile_action': 'review-top','page':str(p), 'limit': '5'},callback=self.parse_review)
header = {#'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0',
'X-Requested-With': 'XMLHttpRequest',
'Host': 'www.zomato.com',
'Accept': '*/*',
'Referer': 'https://www.zomato.com',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'dont_filter':'True' }
url = 'https://www.zomato.com/php/social_load_more.php'
收到的響應是json響應。
jsonresponse = json.load(response)
,我也看到 -
('data==', {u'status': u'success', u'left_count': 0, u'html': u"<script type='text/javascript'>if (typeof initiateLaziness == 'function') initiateLaziness() </script>", u'page': u'1', u'more': 0})
你看到我得到的地位,left_count,頁面,更多的迴應。 但是我對'html'感興趣。不幸的是,它的在糾正值這點我接受,如果通過瀏覽器完成的(檢查網絡通話和驗證)
預計「HTML」是----
<div><a> very long html stuff...............................................<div><script type='text/javascript'>if (typeof initiateLaziness == 'function') initiateLaziness() </script>
我只接收稍後部分
<script>...................................</script>.
真正的html東西丟失。
需要注意的是,我確實收到了回覆,但只有'html'不完整。所有好的休息。我相信這可能與動態生成的html有關。但我對此有任何線索。
scrapy中間件沒有添加內容長度。也不允許我添加一個。將它添加到標題時,響應失敗400。
請求頭被實際發送到服務器:
{'Accept-Language': ['en'], 'Accept-Encoding': ['gzip, deflate,br'], 'Dont_Filter': ['True'], 'Connection': ['keep-alive'], 'Accept': ['*/*'], 'User-Agent': ['Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0'], 'Host': ['www.zomato.com'], 'X-Requested-With': ['XMLHttpRequest'], 'Cookie': ['zl=en; fbtrack=9be27330646d24088c56c2531ea2fbf5; fbcity=7; PHPSESSID=2338004ce3fd540477242c3eaee685168163bd05'], 'Referer': ['https://www.zomato.com'], 'Content-Type': ['application/x-www-form-urlencoded; charset=UTF-8']})
任何一個可以請幫我,如果我在這裏缺少什麼? 或者我可以發送發送內容長度/或讓中間件發送給我? 非常感謝。
我注意到的一件事是,將「Content-Length:50」添加到標題後,響應失敗。而且,中間件不會自動將其添加到請求的標題中。 –