自动接收公司网站上的信息,不知要注意什么?

wenyongjie 2007-11-23 10:30:02
我没做过这方面的,不知有哪位有什么好的意见,谢谢
...全文
273 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ydlchina 2007-11-24
  • 打赏
  • 举报
回复
学习一下
laowang2 2007-11-24
  • 打赏
  • 举报
回复
抓html太麻烦了.
wenyongjie 2007-11-23
  • 打赏
  • 举报
回复
是HTML的,老大想做成像QQ或着是杀毒软件哪样的功能:当网站有新消息发布时,客户端可以立即接受,并显示出来,不知如何解决.郁闷死
lextm 2007-11-23
  • 打赏
  • 举报
回复
如果该网站的信息使用RSS或者Atom之类的Web Service实现,那么客户端自动接收十分简单。

如果只是一般的HTML,就要自己用正则去抓,麻烦多了。
南船 2007-11-23
  • 打赏
  • 举报
回复
许多年前写过类似一个,代码现在看来挺可笑,你看看吧~
思路:把目标网页的HTML代码用"Form1->IdHTTP1->Get("http://www.fjlottery.com/index.htm"); //取得体彩网源码"下下来保存html_str1,然后再用定时器定时后重下与html_str1对比,若用变动再进行你的工作~
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma resource "*.dfm"
TForm1 *Form1;
bool icon;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Timer1->Enabled=true;
Timer1->Interval=90000;
Timer2->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
NMFTP1->Disconnect();
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
Timer1->Interval=600000;
Newdata225=true;
Newdata317=true;
Newdata367=true;
canclose=true;//能否关闭软件
Button2->Enabled=false;
Button1->Cursor=crHourGlass;
StatusBar1->SimpleText="FTP状态:正在连接服务器下载开奖记录!";
edit=Form1->IdHTTP1->Get("http://www.fjlottery.com/index.htm"); //取得体彩网源码
Net225();//取得福建体彩上的开奖记录
html225();//登记到HTML页面上

Net317();
html317();//登记到HTML页面上

Net367();
html367();//登记到HTML页面上

NMFTP1->Host="ftp.51.net";
NMFTP1->Port=21;
NMFTP1->UserID="argo";
NMFTP1->Password="****************";
NMFTP1->Connect();//连接FTP
if(Newdata225){StatusBar1->SimpleText="FTP状态:正在上传22选5开奖记录!";
NMFTP1->Upload("C:\\Program Files\\AutoFTP\\fujian225.htm","");
RichEdit1->Lines->Add("---22选5上传成功---!");}//这是上传
if(Newdata317){StatusBar1->SimpleText="FTP状态:正在上传31选7开奖记录!";
NMFTP1->Upload("C:\\Program Files\\AutoFTP\\fujian317.htm","");
RichEdit1->Lines->Add("---31选7上传成功---!");}//这是上传
if(Newdata367){StatusBar1->SimpleText="FTP状态:正在上传36选7开奖记录!";
NMFTP1->Upload("C:\\Program Files\\AutoFTP\\fujian367.htm","");
RichEdit1->Lines->Add("---36选7上传成功---!");}//这是上传
NMFTP1->Disconnect();//argo.533.net传完

StatusBar1->SimpleText="FTP状态:FTP已断开连接!";
Button1->Cursor=crDefault;
Button2->Enabled=true;
if(canclose&&CheckBox1->Checked)
{Form1->Close();}
}
catch(...) {
Timer1->Interval=600000;
canclose=false;
Button1->Cursor=crDefault;
Button2->Enabled=true;
RichEdit1->Lines->Add("---无法登陆福建体彩网站,下载失败!---");return;
}
}
//---------------------------------------------------------------------------
void TForm1::Net225(void)
{
try{
AnsiString str,str2,str3,str4;
AnsiString hao[6]={""};
int a=5000,chang=edit.Length();
for(int i=5000;i<chang;i++)
{
a++;
str=edit.SubString(a,44);
if(str=="体彩“<font color='#000000'>22选5</font>”第")
{
str2=edit.SubString(a+42,180);
break;
}
}
int a2=0,chang2=str2.Length(),di=1;
for(int i=0;i<chang2;i++)
{
a2++;
str3=str2.SubString(a2,2);
if(str3=="第"){hao[0]=str2.SubString(a2+2,5)+":";}
str4=str2.SubString(a2,1);
if(str4=="&"){hao[di]=str2.SubString(a2-2,2);di++;}
}
RichEdit1->Lines->Add(hao[0]+hao[1]+","+hao[2]+","+hao[3]+","+hao[4]+","+hao[5]);//22选5
str225=hao[0]+hao[1]+","+hao[2]+","+hao[3]+","+hao[4]+","+hao[5];
}
catch(...){
Timer1->Interval=600000;
canclose=false;
Button2->Enabled=true;
Button1->Cursor=crDefault;
RichEdit1->Lines->Add("---22选5无法登陆福建体彩网站,下载失败!---");return;
}
}
//=============================================================

void TForm1::html225(void)
{
try{
AnsiString html225=IdHTTP1->Get("http://argo.html.533.net/fujian225.htm");
AnsiString html225_B;
for(int i=html225.Length()-300;i<html225.Length();i++)
{
if(html225.SubString(i,20)==str225)
{Newdata225=false;RichEdit1->Lines->Add("---22选5记录已是最新! ---");break;}//若南船网页上的和福建体彩的一样就停止
}//for end
if(Newdata225)
{
html225_B=html225.Insert("\n"+str225+"<br>",html225.Length()-17);//增加到html页面
TStrings *CODE1=new TStringList();
CODE1->Text = html225_B;
CODE1->SaveToFile("C:\\Program Files\\AutoFTP\\fujian225.htm");
delete CODE1;
}
}//try end

catch(...){Timer1->Interval=600000;
canclose=false;
Button2->Enabled=true;
Button1->Cursor=crDefault;
RichEdit1->Lines->Add("---连接南船网站5/22失败!!!---");return;
}
}
i_love_pc 2007-11-23
  • 打赏
  • 举报
回复
应该是c/s模式的,而不是自己去抓网页分析。

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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