《[工学]自动填写表单代码.doc》由会员分享,可在线阅读,更多相关《[工学]自动填写表单代码.doc(33页珍藏版)》请在三一办公上搜索。
1、var ie=WScript.createobject(InternetExplorer.Application); var args = WScript.arguments; var followme= if(args.length0) followme+=args(0); ie.Navigate( SynchronizeIE(); var doc=ie.document; doc.forms0.Email.value=yourName; doc.forms0.Passwd.value=密码写在这里; /这是因为PersistentCookie这个checkbox有时候有而有时候没有。 if
2、(doc.forms0.PersistentCookie!=null) doc.forms0.PersistentCookie.checked=false; doc.forms0.submit(); SynchronizeIE(); ie.Visible=true; /等待IE操作结束。 function SynchronizeIE() while(ie.Busy) WScript.Sleep(100); 这段代码可以实现,但是我不太明白这其中的意思,并且实现方法也不太了解, 有谁可以帮忙把这段代码解释一下自动提交表单(2种写法) unit Unit1;interfaceusesWindows
3、, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls,mshtml, OleCtrls, SHDocVw, Mask, bsSkinBoxCtrls,bsSkinData, BusinessSkinForm, bsSkinCtrls, ExtCtrls,IdGlobal,mmsystem,shellapi;typeTForm1 = class(TForm) WebBrowser1: TWebBrowser; Memo1: TMemo; bsBusinessSkinForm1: T
4、bsBusinessSkinForm; bsSkinData1: TbsSkinData; bsSkinEdit1: TbsSkinEdit; bsSkinEdit2: TbsSkinEdit; bsCompressedStoredSkin1: TbsCompressedStoredSkin; bsSkinButton1: TbsSkinButton; bsSkinLabel1: TbsSkinLabel; bsSkinLabel2: TbsSkinLabel; bsSkinEdit3: TbsSkinEdit; bsSkinLabel3: TbsSkinLabel; bsSkinStdLab
5、el1: TbsSkinStdLabel; bsSkinEdit4: TbsSkinEdit; bsSkinEdit5: TbsSkinEdit; bsSkinLabel4: TbsSkinLabel; bsSkinLabel5: TbsSkinLabel; bsSkinLabel6: TbsSkinLabel; bsSkinEdit6: TbsSkinEdit; Timer1: TTimer; bsSkinButton2: TbsSkinButton; bsSkinStdLabel2: TbsSkinStdLabel; bsSkinStdLabel3: TbsSkinStdLabel; bs
6、SkinButton3: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinButton5: TbsSkinButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; procedure FormCreate(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure bsSkinButton
7、3Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton5Click(Sender: TObject); procedure Label1Click(Sender: TObject); procedure Label2Click(Sender: TObject); procedure Label3Click(Sender: TObject); procedure Labe
8、l1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Label2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Label3MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);private function StrReplace(S, OldPattern, NewPattern: string): string; Privat
9、e declarations public Public declarations end;varForm1: TForm1;implementation$R *.dfmprocedure TForm1.FormCreate(Sender: TObject);begin/WebBrowser1.Navigate();end;procedure TForm1.bsSkinButton2Click(Sender: TObject);vari,starnum,endnum,d,m:integer;restr:string ;beginmemo1.Lines.Clear;starnum:= strto
10、int(bsSkinEdit4.text );endnum:= strtoint(bsSkinEdit5.text );for i:= starnum to endnum dobegin if (length(inttostr(i)strtoint(bsSkinEdit6.text) ) then begin restr:=RightStr(inttostr(i),strtoint(bsSkinEdit6.text) ; end else begin restr:=inttostr(i); d:=strtoint(bsSkinEdit6.text)-length(restr); if (d0)
11、 then begin for m:=1 to d do begin restr:=0+restr; end; end ; restr:=StrReplace(bsSkinEdit2.Text,(*),restr); memo1.Lines.add(restr); end;end;WebBrowser1.Navigate(memo1.Lines.Strings0);memo1.SetFocus;memo1.SelStart:=0;memo1.SelLength:=length(memo1.Lines.Strings0);end;function TForm1.StrReplace(S,OldP
12、attern,NewPattern:string):string;vari,m:integer;prestr , endstr :string;/temp:string;begin i:=pos(OldPattern,s); if i0 then begin prestr:=copy(s,1,i-1) ; m:=length(OldPattern) ; endstr:=copy(s,i+m,(length(s)-(i+m)+1); result:=prestr+NewPattern+endstr; end else begin result:=s; end;end;procedure TFor
13、m1.Timer1Timer(Sender: TObject);vari:integer;Doc:IHTMLDocument2;/FormElement:IHTMLFormElement;form:ihtmlformelement;/userinputelement:ihtmlinputelement;mes: ihtmltextareaelement;begin WebBrowser1.Navigate(memo1.Lines.Strings0); /回帖的操作 WebBrowser1.SetFocus; doc:=webbrowser1.document as ihtmldocument2
14、; form:=(doc.all.item(postform,0) as ihtmlformelement); mes:=(doc.all.item(message,0) as ihtmltextareaelement); /doc.all.item(message). if (mesnil) and (formnil) then begin mes.value:=bsSkinEdit1.text; form.submit; end; if i0 then begin WebBrowser1.Navigate(memo1.Lines.Strings0); memo1.Lines.Delete(
15、0); i:=memo1.Lines.Count; bsSkinStdLabel3.Caption:=inttostr(i)+个网址; end else begin Timer1.Enabled:=false; end; Application.ProcessMessages;end;procedure TForm1.bsSkinButton3Click(Sender: TObject);beginmemo1.Lines.Clear;end;procedure TForm1.bsSkinButton1Click(Sender: TObject);begin Timer1.Interval:=s
16、trtoint(bsSkinEdit3.text)*1000; Timer1.Enabled:=true;end;procedure TForm1.bsSkinButton4Click(Sender: TObject);beginTimer1.Enabled:=false;end;procedure TForm1.bsSkinButton5Click(Sender: TObject);varDoc:IHTMLDocument2;/FormElement:IHTMLFormElement;form:ihtmlformelement;/userinputelement:ihtmlinputelem
17、ent;mes: ihtmltextareaelement;begin doc:=webbrowser1.document as ihtmldocument2; form:=(doc.all.item(postform,0) as ihtmlformelement); mes:=(doc.all.item(message,0) as ihtmltextareaelement); /doc.all.item(message). if (mesnil) and (formnil) then begin mes.value:=bsSkinEdit1.text; /pwdinputelement:=(
18、doc.all.item(password,0) as ihtmlinputelement); /pwdinputelement.value:=edit2.text; form.submit; end;end;procedure TForm1.Label1Click(Sender: TObject);beginShellExecute(0, open, pchar(http:/www.sou-), nil, nil, SW_SHOWMAXIMIZED);end;procedure TForm1.Label2Click(Sender: TObject);beginShellExecute(0,
19、open, pchar(), nil, nil, SW_SHOWMAXIMIZED);end;procedure TForm1.Label3Click(Sender: TObject);beginShellExecute(0, open, pchar(), nil, nil, SW_SHOWMAXIMIZED);end;procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);begin Label1.Font.Color:=clRed;end;procedure TForm1.Lab
20、el2MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);begin Label2.Font.Color:=clRed;end;procedure TForm1.Label3MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);begin Label3.Font.Color:=clRed;end;end.源码unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Grap
21、hics, Controls, Forms,Dialogs, StdCtrls, OleCtrls, SHDocVw;typeTForm1 = class(TForm)Button1: TButton;Edit1: TEdit;Edit2: TEdit;WebBrowser1: TWebBrowser;Edit3: TEdit;procedure SetupIII();procedure Button1Click(Sender: TObject);procedure WebBrowser1DocumentComplete(Sender: TObject;const pDisp: IDispat
22、ch; var URL: OleVariant);private Private declarations public Public declarations end;varForm1: TForm1;implementation$R *.dfmprocedure TForm1.SetupIII(); VarMItem,TempItem:Olevariant;TempX:Integer;beginMItem:=WebBrowser1.Document;For TempX:=0 to MItem.All.Length - 1 dobeginTempItem:=MItem.All.Item(Te
23、mpX);IF TempItem.tagName = INPUT thenBeginIF TempItem.Name=subjectthenBeginTempItem.value:=edit1.text;End; /写题目End;IF TempItem.tagName = TEXTAREA thenBeginIF TempItem.Name=messagethenBeginTempItem.value:=edit1.text;End; /写内容End;IF (TempItem.tagName = INPUT) and (TempItem.type=submit) thenBeginTempIt
24、em.Click; /发表帖子 提交按纽end;End;End;procedure TForm1.Button1Click(Sender: TObject);beginWebBrowser1.Navigate(edit3.text); /登录页面 改成你的网址了form1.FocusControl(edit1);/焦点转移到edit1end;procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;const pDisp: IDispatch; var URL: OleVariant); beginSetupIII;end;end
25、.用java实现提取指定网页中的表格数据? 浏览次数:869次悬赏分:15 | 解决时间:2009-8-5 23:19 | 提问者:它山之默 想用java编程来实现抽取指定网站上的一些表格数据内容,比如买书的网站上,有新书发布,我想把所有的新书的信息提取出来,比如书名,作者,出版社等,并导入数据库,请问如何实现,要相关的源代码。谢谢!问题补充: 2楼的不错,但不是我想要的,仍很感谢,我想得到的是纯用java,连接网页,并从中下其中表格中的数据,然后用于更新数据库,-不是java script用网页部分来实现-我想得到的是给一个网页,用java连接并分析下载到其中表格的数据到本地,知道的发给我,
26、谢谢了最佳答案 把下面代码复制到文本文档中,然后将文本文档改成.html形式这个是提取表格中的数据的方法,看看是你想要的不 New Document !- /获得table的tr td等属性 function getTableAtt() alert(该table有+document.all.oTabless.rows.length+个tr) for (i=0; i document.all.oTabless.rows.length; i+) /循环每个tr里的td for (j=0; j 1234 5678 这是一个web搜索的基本程序,从命令行输入搜索条件(起始的URL、处理url的最大数、
27、要搜索的字符串), 它就会逐个对Internet上的URL进行实时搜索,查找并输出匹配搜索条件的页面。 这个程序的原型来自java编程艺术, 为了更好的分析,站长去掉了其中的GUI部分,并稍作修改以适用jdk1.5。以这个程序为基础,可以写出在互联网上搜索 诸如图像、邮件、网页下载之类的“爬虫”。 先请看程序运行的过程: D:javajavac SearchCrawler.java(编译) D:javajava SearchCrawler http:/127.0.0.1:8080/zz3zcwbwebhome/index.jsp 20 java Start searching. result:
28、 searchString=java http:/127.0.0.1:8080/zz3zcwbwebhome/index.jsp http:/127.0.0.1:8080/zz3zcwbwebhome/reply.jsp http:/127.0.0.1:8080/zz3zcwbwebhome/learn.jsp http:/127.0.0.1:8080/zz3zcwbwebhome/download.jsp http:/127.0.0.1:8080/zz3zcwbwebhome/article.jsp http:/127.0.0.1:8080/zz3zcwbwebhome/myexample/
29、jlGUIOverview.htm http:/127.0.0.1:8080/zz3zcwbwebhome/myexample/Proxooldoc/index.html http:/127.0.0.1:8080/zz3zcwbwebhome/view.jsp?id=301 http:/127.0.0.1:8080/zz3zcwbwebhome/view.jsp?id=297 http:/127.0.0.1:8080/zz3zcwbwebhome/view.jsp?id=291 http:/127.0.0.1:8080/zz3zcwbwebhome/view.jsp?id=286 http:/
30、127.0.0.1:8080/zz3zcwbwebhome/view.jsp?id=285 http:/127.0.0.1:8080/zz3zcwbwebhome/view.jsp?id=284 http:/127.0.0.1:8080/zz3zcwbwebhome/view.jsp?id=276 http:/127.0.0.1:8080/zz3zcwbwebhome/view.jsp?id=272 又如: D:javajava SearchCrawler 20 java Start searching. result: searchString=java class=a2 class=a8
31、class=a2 class=a8 class=a8 class=a2 class=a3 class=a3 D:java 下面是这个程序的源码 view plaincopy to clipboardprint?import java.util.*; import .*; import java.io.*; import java.util.regex.*; / 搜索Web爬行者 public class SearchCrawler implements Runnable /* disallowListCache缓存robot不允许搜索的URL。 Robot协议在Web站点的根目录下设置一个ro
32、bots.txt文件, *规定站点上的哪些页面是限制搜索的。 搜索程序应该在搜索过程中跳过这些区域,下面是robots.txt的一个例子: # robots.txt for User-agent: * Disallow: /cgi-bin/ Disallow: /registration # /Disallow robots on registration page Disallow: /login */ private HashMap String,ArrayList disallowListCache = new HashMap String,ArrayList(); ArrayList
33、errorList= new ArrayList();/错误信息 ArrayList result=new ArrayList(); /搜索到的结果 String startUrl;/开始搜索的起点 int maxUrl;/最大处理的url数 String searchString;/要搜索的字符串(英文) boolean caseSensitive=false;/是否区分大小写 boolean limitHost=false;/是否在限制的主机内搜索 public SearchCrawler(String startUrl,int maxUrl,String searchString) th
34、is.startUrl=startUrl; this.maxUrl=maxUrl; this.searchString=searchString; public ArrayList getResult() return result; public void run()/启动搜索线程 crawl(startUrl,maxUrl, searchString,limitHost,caseSensitive); /检测URL格式 private URL verifyUrl(String url) / 只处理HTTP URLs. if (!url.toLowerCase().startsWith(ht
35、tp:/) return null; URL verifiedUrl = null; try verifiedUrl = new URL(url); catch (Exception e) return null; return verifiedUrl; / 检测robot是否允许访问给出的URL. private boolean isRobotAllowed(URL urlToCheck) String host = urlToCheck.getHost().toLowerCase();/获取给出RUL的主机 /System.out.println(主机=+host); / 获取主机不允许搜
36、索的URL缓存 ArrayList disallowList =disallowListCache.get(host); / 如果还没有缓存,下载并缓存。 if (disallowList = null) disallowList = new ArrayList(); try URL robotsFileUrl =new URL(http:/ + host + /robots.txt); BufferedReader reader =new BufferedReader(new InputStreamReader(robotsFileUrl.openStream(); / 读robot文件,创
37、建不允许访问的路径列表。 String line; while (line = reader.readLine() != null) if (line.indexOf(Disallow:) = 0) /是否包含Disallow: String disallowPath =line.substring(Disallow:.length();/获取不允许访问路径 / 检查是否有注释。 int commentIndex = disallowPath.indexOf(#); if (commentIndex != - 1) disallowPath =disallowPath.substring(0, commentIndex);/去掉注释 disallowPath = disallowPath.trim(); disallowList.add(disallowPath); / 缓存此主机不允许访问的路径。 disall