2008年1月5日土曜日

4-2:Extract links

A web page can contain links. If you want to get all links in a page, how do you extract it? See the properties one by one? Open the source by text and check all lines? When there are a few links, it’s very easy. But if there are hundreds of links, I wouldn’t want to think the horrible situation.

This script visits yahoo.com and extracts all links in a page and pastes it to notepad
----------
LINK = ""
IE = CREATEOLEOBJ("InternetExplorer.Application")
IE.visible = True
IE.navigate("http://www.yahoo.com")
REPEAT
SLEEP(0.1)
UNTIL !IE.busy AND IE.readystate = 4
AMOUNT = IE.document.links.length - 1
FOR A = 0 TO AMOUNT
LINK = LINK + IE.document.links[A].href + "<#CR>"
NEXT
NOTE = EXEC("notepad")
SENDSTR(NOTE,LINK)
----------
Sample script No.004
Get script :<http://sky.geocities.jp/uwsc_uwsc_uwsc/04.txt>

The script, which extracts links containing a keyword, is also available. This script visits the site and extracts links containing "www" as a keyword and pastes it to notepad.

----------
LINK = ""
IE = CREATEOLEOBJ("InternetExplorer.Application")
IE.visible = True
IE.navigate("http://www.yahoo.com")

REPEAT
SLEEP(0.1)
UNTIL !IE.busy AND IE.readystate = 4
AMOUNT = IE.document.links.length - 1
FOR A = 0 TO AMOUNT
IFB POS("www",IE.document.links[A].href) > 0
LINK = LINK + IE.document.links[A].href + "<#CR>"
ENDIF
NEXT
NOTE = EXEC("notepad")
SENDSTR(NOTE,LINK)
-----------
Sample script No.005
Get script :<http://sky.geocities.jp/uwsc_uwsc_uwsc/05.txt>

0 件のコメント: