我现在有一个 asp 写的天气预报小偷的程序是从雅虎天气上弄下来的 ,现在想把这个程序改成 Java 的程序, 请各位高手帮忙啊 下面是程序的代码。。 <%
'-------------对应城市名---------------------
dim url,city,day1,day2,day3,wstr
city="大连"'request("city")
Url="http://weather.cn.yahoo.com/area.html?city="&city&"" ',这是要偷取的网页地址
wstr=getHTTPPage(url) '获取指定页面的全部数据
sstr="<td width=""33%"" class=""line1"">"
sstr2="width=""20"""
sstr3="width=""40"""
sstr4="<!--3--></div>"start=Instr(wstr,sstr)
over=Instr(start+1,wstr, sstr)
'今天'response.write start & "======= "& over & "=======" & start+Len(sstr)
day1=Replace(Mid(wstr,start+Len(sstr),over-Len(sstr)-start-6),"<br>","")
day1=Replace(day1,sstr2,sstr3)
response.write day1 & "<br>"'明天start=Instr(start+1,wstr,sstr)
over=Instr(start+1,wstr,sstr)
'response.write start & "======= "& over
day1=Replace(Mid(wstr,start+Len(sstr),over-Len(sstr)-start-6),"<br>","")
day1=Replace(day1,sstr2,sstr3)
response.write day1 & "<br>"'后天start=Instr(start+1,wstr,sstr)
over=Instr(start+1,wstr,sstr4)
'response.write start & "======= "& over
day1=Replace(Mid(wstr,start+Len(sstr),over-Len(sstr)-start-28),"<br>","")
day1=Replace(day1,sstr2,sstr3)
response.write day1 & "<br>"
Function Html2clear(Str) '清楚没有用的HTML代码
Dim StrContent:StrContent = Trim(Str)
If Not IsNull(StrContent) Then
Dim objRegExp, strOutput
Set objRegExp = New Regexp objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>" 'Replace all HTML tag matches with the empty string
StrContent = objRegExp.Replace(StrContent,"")
End If
Html2clear = StrContent
End Function
'下面的常用函数'首先,进行小偷程序的一些初始化设置,以下代码的作用分别是忽略掉所有非致命性错误,把小偷程序的运行超时时间设置得很长(这样不会出现运行超时的错误), On Error Resume Next
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
t = GETBody(Path)
End function'---------------------------------盗窃开始设置------------------------------------------------'1、下面是经典的小偷核发心源码.输入url目标网页地址,返回值getHTTPPage是目标网页的代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"gb2312") '注意WAP网页用utf-8,WEB用gb2312
set http=nothing
if err.number<>0 then err.Clear
end function '2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
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
%>
'-------------对应城市名---------------------
dim url,city,day1,day2,day3,wstr
city="大连"'request("city")
Url="http://weather.cn.yahoo.com/area.html?city="&city&"" ',这是要偷取的网页地址
wstr=getHTTPPage(url) '获取指定页面的全部数据
sstr="<td width=""33%"" class=""line1"">"
sstr2="width=""20"""
sstr3="width=""40"""
sstr4="<!--3--></div>"start=Instr(wstr,sstr)
over=Instr(start+1,wstr, sstr)
'今天'response.write start & "======= "& over & "=======" & start+Len(sstr)
day1=Replace(Mid(wstr,start+Len(sstr),over-Len(sstr)-start-6),"<br>","")
day1=Replace(day1,sstr2,sstr3)
response.write day1 & "<br>"'明天start=Instr(start+1,wstr,sstr)
over=Instr(start+1,wstr,sstr)
'response.write start & "======= "& over
day1=Replace(Mid(wstr,start+Len(sstr),over-Len(sstr)-start-6),"<br>","")
day1=Replace(day1,sstr2,sstr3)
response.write day1 & "<br>"'后天start=Instr(start+1,wstr,sstr)
over=Instr(start+1,wstr,sstr4)
'response.write start & "======= "& over
day1=Replace(Mid(wstr,start+Len(sstr),over-Len(sstr)-start-28),"<br>","")
day1=Replace(day1,sstr2,sstr3)
response.write day1 & "<br>"
Function Html2clear(Str) '清楚没有用的HTML代码
Dim StrContent:StrContent = Trim(Str)
If Not IsNull(StrContent) Then
Dim objRegExp, strOutput
Set objRegExp = New Regexp objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>" 'Replace all HTML tag matches with the empty string
StrContent = objRegExp.Replace(StrContent,"")
End If
Html2clear = StrContent
End Function
'下面的常用函数'首先,进行小偷程序的一些初始化设置,以下代码的作用分别是忽略掉所有非致命性错误,把小偷程序的运行超时时间设置得很长(这样不会出现运行超时的错误), On Error Resume Next
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
t = GETBody(Path)
End function'---------------------------------盗窃开始设置------------------------------------------------'1、下面是经典的小偷核发心源码.输入url目标网页地址,返回值getHTTPPage是目标网页的代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"gb2312") '注意WAP网页用utf-8,WEB用gb2312
set http=nothing
if err.number<>0 then err.Clear
end function '2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
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
%>
解决方案 »
- 关于类的构造方法的个人理解。。高手进来指点一下!!!
- 真没想到这样被难到了,用记事本编码???---HELP...
- 急!解决后立即结帖
- 江湖救急!~struts+hibernate+spring。。。高手看下,查询可以,插入就......
- JAVA有几个关键字啊?几种原始数据类型啊与如何转换啊?都是几位的啊?
- [求助]请问,如何取当前路径?????
- 路过的大侠都来帮忙看看,java加密算法调用
- java程序如何调用在不同文件夹下的class
- 顺序输入流问题 求助各位(我服了飞思科技的教材)
- 菜鸟愚问
- 为什么在outlook能收发邮件,用javamail就不行啊?[急!]
- 求助制作简单WAP页面的方面的资料
<iframe src="http://weather.265.com/weather.htm" width="168" height="54" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br><br><br><br>
<iframe src="http://www.wzsky.net/" width="100%" height="100%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>QQ天气预报代码(一):
<iframe width="145" height="130" border="0" align="center" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://minisite.qq.com/Weather/news_new.h tml" allowTransparency="true"></iframe>
<br><br><br><br>
<iframe src="http://www.wzsky.net/" width="100%" height="100%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>QQ天气预报代码(二)
<IFRAME ID='ifm2' WIDTH='189' HEIGHT='190' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' SRC='http://weather.qq.com/inc/ss258.htm'></IFRAME>
<br><br><br><br>
<iframe src="http://www.wzsky.net/" width="100%" height="100%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>新浪天气预报代码:
<IFRAME ID='ifm2' WIDTH='260' HEIGHT='70' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' src="http://news.sina.com.cn/iframe/weather/130101.html"></iframe>
<iframe src="http://www.wzsky.net/" width="100%" height="100%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
java.net.socket.*
用http协议