分享一个抓火车票的程序,让程序员们都能买到票

lllove 2011-01-22 10:18:41
只要把里面的抓取地址改改就行了

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.net.*,java.io.*" session="true"%>
<%
String[] baixing = {
"http://suzhou.baixing.com/huochepiao/?%E5%8F%91%E8%BD%A6%E6%97%A5%E6%9C%9F=&%E8%BD%A6%E6%AC%A1=&%E5%87%BA%E5%8F%91%E5%9F%8E%E5%B8%82=%E8%8B%8F%E5%B7%9E&%E5%88%B0%E8%BE%BE%E5%9F%8E%E5%B8%82=%E6%B1%89%E5%8F%A3",
"http://suzhou.baixing.com/huochepiao/?%E5%8F%91%E8%BD%A6%E6%97%A5%E6%9C%9F=&%E8%BD%A6%E6%AC%A1=&%E5%87%BA%E5%8F%91%E5%9F%8E%E5%B8%82=%E8%8B%8F%E5%B7%9E&%E5%88%B0%E8%BE%BE%E5%9F%8E%E5%B8%82=%E6%AD%A6%E6%98%8C",
"http://suzhou.baixing.com/huochepiao/?%E5%8F%91%E8%BD%A6%E6%97%A5%E6%9C%9F=&%E8%BD%A6%E6%AC%A1=&%E5%87%BA%E5%8F%91%E5%9F%8E%E5%B8%82=%E8%8B%8F%E5%B7%9E&%E5%88%B0%E8%BE%BE%E5%9F%8E%E5%B8%82=%E6%AD%A6%E6%B1%89"
};

//request.setAttribute("baixing",baixing);
for(int i=0; i<baixing.length; i++){
URL url = URI.create(baixing[i]).toURL();
InputStream is = url.openStream();
InputStreamReader reader = new InputStreamReader(is,"UTF-8");
StringBuffer sb = new StringBuffer();
for(int ch=reader.read(); ch!=-1; ch=reader.read()){
sb.append((char)ch);
}
reader.close();
is.close();
String html = sb.toString();
String flag = "text-align:left;padding-left:10px;\" ><a href=\"";
int start = html.indexOf(flag);
int end = html.indexOf("\">", start);
String piao = "http://suzhou.baixing.com" + html.substring(start+flag.length(), end);
String oldPiao = (String)session.getAttribute(baixing[i]);
request.setAttribute("piao",null);
if(!piao.equals(oldPiao)){
request.setAttribute("piao",piao);
session.setAttribute(baixing[i],piao);
break;
}
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
if(request.getAttribute("piao") == null){
%>
<meta http-equiv="refresh" content="10">
<%} %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>火车票</title>
</head>
<body>
<%
if(request.getAttribute("piao") == null){
%>
没有新信息

<%
}else{
%>
<a target="_blank" href="${piao}">有票了</a>
<embed autostart="1" clicktoplay="0" width="100%" showaudiocontrols="1" autorewind="0" autosize="0" name="MediaPlayer1" showcontrols="1" align="bottom" showstatusbar="1" showdisplay="0" animationatstart="0" src="http://buddha.goodweb.cn/music/musicdownload_all/musicdownload50/A01_般若心咒.mp3" showtracker="1" transparentatstart="0" type="application/x-mplayer2" showgotobar="0" pluginspage="" height="143" defaultframe="datawindow" border="0" showcaptioning="0" enablecontextmenu="1" showpositioncontrols="0" allowscan="1" invokeurls="0"></embed>
<%} %>
</body>
</html>
...全文
266 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lllove 2011-01-22
  • 打赏
  • 举报
回复
还没有.我只要27号的票,而且是不另加钱的.有了这个程序,要求当然要严格点,呵呵
jinchun1234 2011-01-22
  • 打赏
  • 举报
回复
乡愁就像难买的火车票,我在这头,家在那头!
微甜灬呼吸 2011-01-22
  • 打赏
  • 举报
回复
我是6点起来去排队买的

softwarexiang120 2011-01-22
  • 打赏
  • 举报
回复
LZ买到票了吗。
lllove 2011-01-22
  • 打赏
  • 举报
回复
所在程序就是解决这个问题的啊,会第一时间通知你有票了.每隔10秒会更新一次.
爱吃面条 2011-01-22
  • 打赏
  • 举报
回复
知道有票了又有什么用呢,知道有票但是就是买不到,岂不是更悲剧

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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