回 帖 发 新 帖 刷新版面

主题:xmlhttp写小偷程序问题,IP不对??求解

有ASP高手不?请教一个问题,
小偷程序的编写,用他来偷取天气预报,YAHOO。COM的
我写好了,可以发现是根据服务器断的IP来偷取的,请问有没有有根据客户断来偷取的啊办法啊用的是XMLHTTP
可能是自己技术不怎么好,我用抓取yahoo首页的html在,取出他那里的显示天气的代码,可是我发现他的网页天天有变化,我抓取的东西会不正确,抓了一些没用的东西,
另外一个问题就是,发现,是根据服务器断的IP来显示天气,也就是说抓取代码是从服务器断抓的,也就是显示了服务器那个地方的天气预报
哎!!!郁闷
请问有没有好的方法,能正确的抓到天气预报,

回复列表 (共14个回复)

沙发

http://blog.programfan.com/article.asp?id=28283
你要的是不是这个

板凳

不是啊。不过类似了,我想要的是能根据访问者的所在地来显示访问者,哪个城市的天气,

3 楼


  <%
'声明一个函数,用于读取远程文件

function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then 
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear 
end function
'声明一个函数,对读取的远程文件进行汉字转码
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText 
objstream.Close
set objstream = nothing
End Function


'要偷的网页的地址,你只需要从http://www.weathercn.com/找到你要偷取的页面就行
Url="http://www.weathercn.com/forecast/citydetail.jsp?sta_id="&cityid
Html = getHTTPPage(Url) '开始读取远程地址





不同的城市有不同的cityid,具体城市对应的id你可以去那个网站自己看看,

然后就是从取到的值中找到你要的数据,用正则表达式就可以了。你可以仔细分析一下他的代码找到特点,我的代码写得不太好,不好意思拿出来显,你要是需要就留言吧,不过最好你能自己写。
    

4 楼

要,谢谢
我写了个,大概是你说的这个思路了,只不我没用哪个正折表达试,
可是显示的是服务器哪个城市的天气,也就是说我们抓的时候会在服务器断抓了,这样就达不到我要的结果哦
象《%%》里面的东西多是在服务器断执行啊

5 楼

雅虎的天气在这里抓
http://weather.cn.yahoo.com/weather.html?city=%E8%B4%B5%E9%98%B3

city后面的就是城市,不过具体那个城市我就不知道了。

6 楼


'获取近期天气
'获取日期    
    Set regEx = New RegExp            ' 建立正则表达式。
    regEx.Pattern = "<td colspan=""3"" class=""font_red""><strong>(\d+)月(\d+)日(\d+)时至(\d+)月(\d+)日(\d+)时"            ' 设置模式。
    regEx.IgnoreCase = True        ' 设置区分大小写。
    regEx.Global = True            ' 搜索全部匹配。
    Set Matches = regEx.Execute(html)    ' 执行搜索。
    redim d(35)
    For Each Match in Matches  ' 循环遍历Matches集合。
    for i=0 to 5
    d(i)=Match.SubMatches(i)
    Next
    next
    set regEx = nothing
'获取日期    
'获取气象    

    Set regEx = New RegExp            ' 建立正则表达式。
    regEx.Pattern = "<img alt=""([\u4e00-\u9fa5]*)"" src=""/forecasticon/60/[\w\.]+"" width=""60"" height=""60"">"        ' 设置模式。
    regEx.IgnoreCase = True        ' 设置区分大小写。
    regEx.Global = True            ' 搜索全部匹配。
    Set Matches = regEx.Execute(html)    ' 执行搜索。
    i=6
    For Each Match in Matches  ' 循环遍历Matches集合。
    d(i)=Match.SubMatches(0)
    i=i+1
    Next

    set regEx = nothing
'获取气象    
'获取温度
    Set regEx = New RegExp            ' 建立正则表达式。
    regEx.Pattern = "([-]?\d+)℃~([-]?\d+)℃"        ' 设置模式。
    regEx.IgnoreCase = True        ' 设置区分大小写。
    regEx.Global = True            ' 搜索全部匹配。
    Set Matches = regEx.Execute(html)    ' 执行搜索。
    i=8
    For Each Match in Matches  ' 循环遍历Matches集合。
    d(i)=Match.SubMatches(0)
    i=i+1
    d(i)=Match.SubMatches(1)
    Next
    set regEx = nothing
'获取温度    

7 楼

'获取天气详情
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "<td[ width=""176""| width=""96""]* class=""font_sl"">([\u4e00-\u9fa5]*:([^<]+)|([\u4e00-\u9fa5]+))"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=10
                For Each Match in Matches       ' 循环遍历Matches集合。
                if match.submatches(1)="" then
                d(i)=Match.SubMatches(2)
                else
                d(i)=match.submatches(1)
                end if
                i=i+1 
                Next
                set regEx = nothing     
'获取天气详情

'获取指数
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "(<td align=""center"">|<td align=""center""><span class=""font_sl"">|<td align=""center"" class=""qushi""><span class=""font_sl"">)(&nbsp;)?([-]?[\d+]+)"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=20
                For Each Match in Matches       ' 循环遍历Matches集合。
                d(i)=Match.SubMatches(2)
                i=i+1 
                Next
                set regEx = nothing    
'获取指数
'获取指数内容
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "(<td><span class=""font_sl"">|<td class=""qushi""><span class=""font_sl"">)(&nbsp;)?([^<]+)"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=28
                For Each Match in Matches       ' 循环遍历Matches集合。
                d(i)=trim(Match.SubMatches(2))
                i=i+1 
                Next
                set regEx = nothing      
'获取指数内容
'获取近期天气

8 楼

'获取中期天气
'日期
                redim e(39)
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "l""><strong>(\d+)年(\d+)月(\d+)日"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=0
                For Each Match in Matches       ' 循环遍历Matches集合。
                e(i)=trim(Match.SubMatches(0))
                i=i+1
                e(i)=trim(Match.SubMatches(1))
                i=i+1
                e(i)=trim(Match.SubMatches(2))
                i=i+8
                Next
                set regEx = nothing      
'日期
'气象
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = ">(<img alt=""([\u4e00-\u9fa5]+)"" src=""/forecasticon/20/[\w\.]+"" width=""20"" height=""20"">)(<img alt=""([\u4e00-\u9fa5]+)"" src=""/forecasticon/20/[\w\.]+"" width=""20"" height=""20"">)?"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=3
                For Each Match in Matches       ' 循环遍历Matches集合。
                e(i)=trim(Match.SubMatches(1))
                i=i+1 
                e(i)=trim(Match.SubMatches(3))
                i=i+9
                Next
                set regEx = nothing      
'气象
'温度
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "<strong>(\d+)<strong>℃</strong></strong></span><strong>~(\d+)"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=5
                For Each Match in Matches       ' 循环遍历Matches集合。
                e(i)=trim(Match.SubMatches(0))
                i=i+1 
                e(i)=trim(Match.SubMatches(1))
                i=i+9
                Next
                set regEx = nothing      
'温度

9 楼

'风力
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "(<img alt=""([\u4e00-\u9fa5]+[\d]+[\u4e00-\u9fa5]+)"" src=""/forecasticon/wind/([\w]+_[\d]+).gif"" width=""27"" height=""30"">)(<img alt=""([\u4e00-\u9fa5]+[\d]+[\u4e00-\u9fa5]+)"" src=""/forecasticon/wind/([\w]+_[\d]+).gif"" width=""27"" height=""30"">)?"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=7
                For Each Match in Matches       ' 循环遍历Matches集合。
                e(i)=trim(Match.SubMatches(1))
                i=i+1
                e(i)=trim(Match.SubMatches(4))
                i=i+9
                Next
                set regEx = nothing      
'风力
'趋势
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "<img src=""image/([\w]+).gif"" >"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=9
                For Each Match in Matches       ' 循环遍历Matches集合。
                e(i)=trim(Match.SubMatches(0))
                i=i+10
                Next
                set regEx = nothing
'趋势
'获取中期天气    

10 楼

'获取天气实况
'获取日期
                redim f(7)
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "d""><strong>(\d+)年(\d+)月(\d+)"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=0
                For Each Match in Matches       ' 循环遍历Matches集合。
                f(i)=Match.SubMatches(0)
                i=i+1
                f(i)=Match.SubMatches(1)
                i=i+1
                f(i)=Match.SubMatches(2)
                Next
                set regEx = nothing
'获取日期                
'获取时间                
                Set regEx = New RegExp            ' 建立正则表达式。
                regEx.Pattern = "i"">[^\d]+(\d+)[\d\u4e00-\u9fa5]+&nbsp;</td>"            ' 设置模式。
                regEx.IgnoreCase = True        ' 设置区分大小写。
                regEx.Global = True            ' 搜索全部匹配。
                Set Matches = regEx.Execute(html)    ' 执行搜索。
                i=3
                For Each Match in Matches       ' 循环遍历Matches集合。
                f(i)=trim(Match.SubMatches(0))
                Next
                set regEx = nothing
'获取时间

我来回复

您尚未登录,请登录后再回复。点此登录或注册