[已解决]求大牛帮忙抓个网页时间表
本帖最后由 kxing 于 2014-9-15 12:11 编辑求大牛帮忙看下这个时间表为什么总是获取不到的呢
http://tv.cntv.cn/epg?channel=cctv1
我抓到了这个网址,但是改换下date就返回0了:
http://tv.cntv.cn/index.php?action=epg-list&date=2014-08-19&channel=cctv1&mode=
感谢各位!!! 不是正则不正则的问题,是那个网址访问后返回数据总是0,抓包也没看到要传什么参数。。。大神求帮助啊。。。 求求高人指点啊,期待。。。。 http://tv.cntv.cn/index.php?action=epg-list&date=2014-08-26&channel=cctv1 顺便给你找个获取源代码的例子
http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=44835&pid=587950&fromuid=7653969 本帖最后由 shqf 于 2014-8-26 14:54 编辑
抓到的网址应该没错,首次访问当天的会成功并获得服务器回复的cookie,再访问其他日期的页面时需要带上cookie,或还需加上Referer等一些信息才能成功。 回复 1# kxing
#include <array.au3>
Global $date="2014-08-25" , $channel="cctv1" , $Cookie=""
$html=GetChannelHtml($date,$channel,2)
_ArrayDisplay($html)
#cs
说明 : $date 要获取的日期. 必须为有效日期格式 YYYY-MM-DD
$channel 要获取的频道名称.必须为网站上已知的有效频道名称
$strmode 返回数据类型 为1 返回文本型不为1返回数组型并处理网址为可直接打开的网址格式
#ce
Func GetChannelHtml($date,$channel,$strmode=1)
$getInfoUrl="http://tv.cntv.cn/index.php?action=epg-list&date="&$date&"&channel="&$channel&"&mode="
$WinHttp=ObjCreate("WinHttp.WinHttprequest.5.1")
$WinHttp.SetTimeouts(60000, 60000, 60000, 3000) ;设置操作超时时间
$WinHttp.Option(4) = 13056 ;忽略错误标志
$WinHttp.Option(6) = True ;为 True 时,当请求页面重定向跳转时自动跳转,False 不自动跳转,截取服务端返回的302状态。
$WinHttp.Open( "Get", $getInfoUrl, False) ;GET 或 POST, Url, False 同步方式;True 异步方式
$WinHttp.SetRequestHeader("Host", "tv.cntv.cn") ;主机
$WinHttp.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0")
$WinHttp.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") ;接受数据类型
$WinHttp.SetRequestHeader("Accept-Language", "zh-CN") ;用户系统语言
$WinHttp.SetRequestHeader("Referer", "http://tv.cntv.cn/epg?channel=cctv1") ;来路
$WinHttp.SetRequestHeader("Connection", "Keep-Alive") ;Close = 不保持连接,Keep-Alive = 保持连接(持久连接)
$WinHttp.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
$WinHttp.SetRequestHeader("Pragma","no-cache")
$WinHttp.Send()
ConsoleWrite("GetChannelHtml "&$WinHttp.Status&@TAB&$WinHttp.StatusText &@CRLF) ;当前 HTTP 状态
$HEADER=$WinHttp.GetAllResponseHeaders()
$WinHttp.WaitForResponse ;等待返回请求,XMLHTTP中也可以使用
$body = BinaryToString($WinHttp.ResponseBody,4)
$WinHttp=0
If $strmode=1 Then
Return $body
Else
$body=StringRegExp($body,'href="(.*)" class="p_name_a">(.*)</a>',3)
For $i=0 To UBound($body)-1 Step 2
$body[$i]="http://tv.cntv.cn"&$body[$i]
Next
Return $body
EndIf
EndFunc
高人终于出手了,感谢楼上。。。
页:
[1]