关于curl 采集 跳转页面

x10n6y 2014-01-20 06:17:29
http://hotel.qunar.com/city/chengdu/dt-7891/?tag=chengdu#fromDate=2014-01-22&toDate=2014-01-23&q=&from=qunarindex&filterid=e6b6c013-e4af-45af-a935-0494a2778416_C&showMap=0&qptype=&QHFP=ZSS_A4C18A85&QHPR=1_1_1_0
需求是 采集上面这个网页,得到其中的各个网站的该酒店 的相关页面 如 携程 : http://hotels.ctrip.com/Domestic/ShowHotelInformation.aspx?hotel=691905&roomId=4137419&StartDate=2014-01-22&DepDate=2014-01-23&ol_sid=&allianceid=&ouid=&utm_medium=&utm_campaign=&utm_source=&isctrip=&token=C8A3FACB1A224789D56D70AED49E1617F961BA3DF27C16A4
但是中间跳转了几次,用curl 的CURLOPT_RETURNTRANSFER 参数 也不好使,请大神些帮助!
...全文
467 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
luciferisnotsatan 2014-01-21
  • 打赏
  • 举报
回复
引用 9 楼 x10n6y 的回复:
[quote=引用 7 楼 luciferisnotsatan 的回复:] 去哪儿的网页里有个携程的连接,这个是body里的html的内容。你要这个连接的话,就得自己去解析去哪儿的网页内容,得到携程的网页地址
就是我解析出来的网址 跳转后 才能得到 携程的,我不知道怎么用curl 去获取跳转后的这个地址[/quote] t2=3111116这个也是一个页面,不是重定向。应该是这个页面里面的代码会去调转到携程的。再解析这个页面,得到里面的东西。 看了下这页的内容,也没直接标出url。是从js代码里得到的。 浏览器里看的不明显,最好就是自己得到server返回的数据(如前面我说的telnet后发get命令),然后看看里面是什么内容。 CURLOPT_FOLLOWLOCATION 这个是要server返回302才有用的,body里写的代码来实现调转和http协议里的重定向(302)没什么关系。
x10n6y 2014-01-21
  • 打赏
  • 举报
回复
引用 7 楼 luciferisnotsatan 的回复:
去哪儿的网页里有个携程的连接,这个是body里的html的内容。你要这个连接的话,就得自己去解析去哪儿的网页内容,得到携程的网页地址
就是我解析出来的网址 跳转后 才能得到 携程的,我不知道怎么用curl 去获取跳转后的这个地址
x10n6y 2014-01-21
  • 打赏
  • 举报
回复
刚才说错了 是这个网址: http://hotel.qunar.com/booksystem/booking.jsp?full=false&ttsSign=b3183222398fea73b52da0fa63851e9b&priceCut=61&tid=10916307&required1=2014-01-22&required2=2014-01-23&payment=0&CPCB=wictrip0000&roomId=4137419&qhsign=e33pP37qvC3insY9pEYsRmR5Pq-iSVmyvAaz5FFNYfFTSChKNY_×tamp=1390207218441&bts=oTf5BlmkMcIgocZjMaC&requestID=c0a8e977-m2vd4-ch05&lpsp=rp&ppb=0&stat=30023&retailPrice=509&detailType=guru&from=qunarindex&sgroup=A&filterid=e6b6c013-e4af-45af-a935-0494a2778416_C&QHFP=ZSD_A4C23AA5&QHP=ZSB_A4C25848&stat2=3111116 它会跳转.
luciferisnotsatan 2014-01-21
  • 打赏
  • 举报
回复
去哪儿的网页里有个携程的连接,这个是body里的html的内容。你要这个连接的话,就得自己去解析去哪儿的网页内容,得到携程的网页地址
luciferisnotsatan 2014-01-21
  • 打赏
  • 举报
回复
引用 5 楼 x10n6y 的回复:
[quote=引用 3 楼 luciferisnotsatan 的回复:] CURLOPT_FOLLOWLOCATION A parameter set to 1 tells the library to follow any Location: header that the server sends as part of a HTTP header. This means that the library will re-send the same request on the new location and follow new Location: headers all the way until no more such headers are returned. CURLOPT_MAXREDIRS can be used to limit the number of redirects libcurl will follow. 这个是指重定向的东西吧。也就是一般server返回302时,location里给的一个新uri。 而你要的那是body里的东西,自己写代码解析吧
body 里面只能提取到连接:http://hotel.qunar.com/city/chengdu/dt-7891/?tag=chengdu#fromDate=2014-01-22&toDate=2014-01-23&q=&from=qunarindex&filterid=e6b6c013-e4af-45af-a935-0494a2778416_C&showMap=0&qptype=&QHFP=ZSS_A4C18A85&QHPR=1_1_1_0 点击之后,它就跳转到这里去了: http://hotels.ctrip.com/Domestic/ShowHotelInformation.aspx?hotel=691905&roomId=4137419&StartDate=2014-01-22&DepDate=2014-01-23&ol_sid=&allianceid=&ouid=&utm_medium=&utm_campaign=&utm_source=&isctrip=&token=C8A3FACB1A224789D56D70AED49E1617F961BA3DF27C16A4 我想要得 也就是后面的这个连接地址;不知道 该怎么弄?[/quote] http://hotel.qunar.com/city/chengdu/dt-7891/?tag=chengdu#fromDate=2014-01-22&toDate=2014-01-23&q=&from=qunarindex&filterid=e6b6c013-e4af-45af-a935-0494a2778416_C&showMap=0&qptype=&QHFP=ZSS_A4C18A85&QHPR=1_1_1_0 这个连接没有自动调转呀,不过是放浏览器里,还是直接telnet后get,都没发现server会重新定向到你说的第二个网址。
x10n6y 2014-01-21
  • 打赏
  • 举报
回复
引用 3 楼 luciferisnotsatan 的回复:
CURLOPT_FOLLOWLOCATION A parameter set to 1 tells the library to follow any Location: header that the server sends as part of a HTTP header. This means that the library will re-send the same request on the new location and follow new Location: headers all the way until no more such headers are returned. CURLOPT_MAXREDIRS can be used to limit the number of redirects libcurl will follow. 这个是指重定向的东西吧。也就是一般server返回302时,location里给的一个新uri。 而你要的那是body里的东西,自己写代码解析吧
body 里面只能提取到连接:http://hotel.qunar.com/city/chengdu/dt-7891/?tag=chengdu#fromDate=2014-01-22&toDate=2014-01-23&q=&from=qunarindex&filterid=e6b6c013-e4af-45af-a935-0494a2778416_C&showMap=0&qptype=&QHFP=ZSS_A4C18A85&QHPR=1_1_1_0 点击之后,它就跳转到这里去了: http://hotels.ctrip.com/Domestic/ShowHotelInformation.aspx?hotel=691905&roomId=4137419&StartDate=2014-01-22&DepDate=2014-01-23&ol_sid=&allianceid=&ouid=&utm_medium=&utm_campaign=&utm_source=&isctrip=&token=C8A3FACB1A224789D56D70AED49E1617F961BA3DF27C16A4 我想要得 也就是后面的这个连接地址;不知道 该怎么弄?
luciferisnotsatan 2014-01-21
  • 打赏
  • 举报
回复
比如你telnet上www.google.com 的80端口,发送 GET http://www.google.com/ HTTP/1.0 然后会收到 HTTP/1.0 302 Found Location: http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q= http://www.google.com.hk/&ust=1390269899151508&usg=AFQjCNF_mtntojglr3O_4fxVlyOEo qtg6w 。。。 这个才是CURLOPT_FOLLOWLOCATION回去试的url
luciferisnotsatan 2014-01-21
  • 打赏
  • 举报
回复
CURLOPT_FOLLOWLOCATION A parameter set to 1 tells the library to follow any Location: header that the server sends as part of a HTTP header. This means that the library will re-send the same request on the new location and follow new Location: headers all the way until no more such headers are returned. CURLOPT_MAXREDIRS can be used to limit the number of redirects libcurl will follow. 这个是指重定向的东西吧。也就是一般server返回302时,location里给的一个新uri。 而你要的那是body里的东西,自己写代码解析吧
x10n6y 2014-01-21
  • 打赏
  • 举报
回复
引用 1 楼 truexf 的回复:
curl_easy_setopt(hCURL,CURLOPT_FOLLOWLOCATION,1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30); // 超时设置,免得程序被堵住 curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1); // 以下3个为重定向设置 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1); 该加的 都加了啊
「已注销」 2014-01-21
  • 打赏
  • 举报
回复
curl_easy_setopt(hCURL,CURLOPT_FOLLOWLOCATION,1L);

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧