我有这个url,它的响应内容,包含一些JSON数据。在
https://www.tripadvisor.com/TypeAheadJson?action=API&types=geo%2Cnbrhd%2Chotel%2Ctheme_park&legacy_format=true&urlList=true&strictParent=true&query=sadaf%20dubai%20hotel&max=6&name_depth=3&interleaved=true&scoreThreshold=0.5&strictAnd=false&typeahead1_5=true&disableMaxGroupSize=true&geoBoostFix=true&neighborhood_geos=true&details=true&link_type=hotel%2Cvr%2Ceat%2Cattr&rescue=true&uiOrigin=trip_search_Hotels&source=trip_search_Hotels&startTime=1516800919604&searchSessionId=BA939B3D93510DABB510328CBF3353131516800881576ssid&nearPages=true
每次我用不同的查询将这个url粘贴到浏览器中,都会得到一个不错的JSON结果。但在这破破烂烂烂的壳里,我没有得到任何结果。这是我的破蜘蛛课:
^{pr2}$对于这段代码,在scrapy shell中,我得到以下结果:
b'{"normalized":{"query":""},"query":{},"results":[],"partial_content":false}'
在scrapy命令行中,通过运行spider,我首先得到了每个url的Forbidden by robots.txt
错误。我将scrapy ROBOTSTXT_OBEY
更改为False
,因此它不符合此文件。现在我为每个请求得到[]
,但我应该得到一个如下的JSON对象:
[
{
"urls":[
{
"url_type":"hotel",
"name":"Sadaf Hotel, Dubai, United Arab Emirates",
"type":"HOTEL",
"url":"\/Hotel_Review-g295424-d633008-Reviews-Sadaf_Hotel-Dubai_Emirate_of_Dubai.html"
}
],
.
.
.
尝试从URL中删除sessionID,也许可以检查一下您的settings.py有多“不友好”。(另见this blog)
但是使用Wget,比如
wget 'https://www.tripadvisor.com/TypeAheadJson?action=API&types=geo%2Cnbrhd%2Chotel%2Ctheme_park&legacy_format=true&urlList=true&strictParent=true&query={}%20dubai%20hotel&max=6&name_depth=3&interleaved=true&scoreThreshold=0.5&strictAnd=false&typeahead1_5=true&disableMaxGroupSize=true&geoBoostFix=true&neighborhood_geos=true&details=true&link_type=hotel%2Cvr%2Ceat%2Cattr&rescue=true&uiOrigin=trip_search_Hotels&source=trip_search_Hotels&startTime=1516800919604&nearPages=true' -O results.json
,可能更容易相关问题 更多 >
编程相关推荐