爬虫高手请进。
发布于 9 年前 作者 jackhutu 5402 次浏览 最后一次编辑是 8 年前 来自 问答

由于一些数据API未提供,所以想爬页面来获取。这是想要抓的页面 http://english.ctrip.com/hotels/shanghai-hotel-detail-436187/baoan-hotel/ 这个页面数据通过AJAX请求来获取。 请求地址:http://english.ctrip.com/hotels/Detail/GetRoomDataJson4Hotels 参数:
var apiParams = { HotelID:436187, checkin:‘2015/05/10’, checkout:‘2015/05/11’, RoomQuantity:1, balanceperiod:‘M’ }; 我用https://github.com/request/request 这个模块来发起POST请求。我尝试了设置Referer,User-Agent,cookie等都无法获取数据 没有报错,响应是成功的,body为空。 不知道是什么原因??很奇怪。希望高手指点。

2 回复

请求参数按照我给的 ` { form:{ HotelID:‘436187’, checkin:‘2015/05/11’, checkout:‘2015/05/12’, RoomQuantity:1, balanceperiod:‘M’

	},
	headers:{
		Accept:'*/*',
   'Accept-Language':'zh-CN,zh;q=0.8',
   'Cache-Control':'max-age=0',
		'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
		Host:'english.ctrip.com',
		'If-Modified-Since':'Thu, 01 Jan 1970 00:00:00 GMT',
		Origin:'http://english.ctrip.com',
		Referer:'http://english.ctrip.com/hotels/shanghai-hotel-detail-436187/baoan-hotel/',
		'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36',
		Cookie:'_abtest_userid=4a2551e9-41af-447f-8faf-0b588ab74749; _ga=GA1.2.193252807.1430045194; __zpspc=9.1.1430045194.1430045194.1%233%7Cwww.torrentkitty.org%7C%7C%7C%7C%23; _jzqco=%7C%7C%7C%7C1430045194284%7C1.2118329252.1430045194127.1430045194127.1430045194128.1430045194127.1430045194128.0.0.0.1.1; zdatactrip=zdatactrip=68be456a3656cac45f80482b2b7d3ea9; Union=AllianceID=110341&SID=554395&OUID=000401app-; ASP.NET_SessionSvc=MTAuOC45Mi4yNDF8OTA5MHxqaW5xaWFvfGRlZmF1bHR8MTQyNzg4MjQ1ODUwNw; ASP.NET_SessionId=jzxrraerfyxfxuwkqmyrazxy; __gads=ID=a7b4b072aa21c6a4:T=1431079305:S=ALNI_MaZ4E7CTn254dSH4KUIaemN76a0YA; TracingUserFlag=2899da3d92e82113; TracingErrorFlag=228a584ff9cc36ad; search_cityId=2; search_displayValue=Shanghai; search_starttime=05-11-2015; search_deptime=05-12-2015; search_optionId=0; search_optionType=; search_lat=0; search_lon=0; search_markland=; intl_ht2=rhs=%5b%7b%22SearchKeyWord%22%3a%22Shanghai%22%2c%22CheckIn%22%3a%2205%2f11%2f2015%22%2c%22CheckOut%22%3a%2205%2f12%2f2015%22%2c%22Url%22%3a%22http%3a%2f%2fenglish.ctrip.com%2fhotels%2flist%3fcity%3d2%26checkin%3d05-11-2015%26checkout%3d05-12-2015%26hotelname%3d%26searchboxArg%3dt%26lat%3d0%26lon%3d0%26display%3dShanghai%26markland%3d%22%7d%5d; __utma=1.193252807.1430045194.1431079285.1431079285.1; __utmb=1.7.10.1431079285; __utmc=1; __utmz=1.1431079285.1.1.utmcsr=cnodejs.org|utmccn=(referral)|utmcmd=referral|utmcct=/topic/554c2aa4b68166372e6001ff; _bfi=p1%3D2000303%26p2%3D2000303%26v1%3D8%26v2%3D7; intl_ht1=h4=2_436187&h2=2015-05-11&h3=2015-05-12; _bfa=1.1430045193814.1ytdl7.1.1430045193814.1431079284336.2.9; _bfs=1.8; Session=SmartLinkCode=cnodejs&SmartLinkKeyWord=&SmartLinkQuary=&SmartLinkHost=cnodejs.org&SmartLinkLanguage=en'
	},
	url:'http://english.ctrip.com/hotels/Detail/GetRoomDataJson4Hotels',

	method:'post'

}

`

@joney-pinkman 非常感谢,我要好好检讨一下我错在哪了,白白浪费了时间。

回到顶部