0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

vbsの作法 その88

Posted at

概要

vbsの作法、調べてみた。
練習問題やってみた。

練習問題

IE11で、再帰的にリンクを辿って、タイトルとディスクリプションを取得せよ。

サンプルコード


Sub crawl2(url)
	Dim ws
	Set ws = WScript.CreateObject("WScript.Shell")
	Dim objIE
	Set objIE = CreateObject("InternetExplorer.Application")
	objIE.Visible = True
	objIE.Navigate url
	ws.AppActivate("Internet Explorer")
	Do While objIE.ReadyState <> 4 Or objIE.Busy = True
	    WScript.Sleep 100
	Loop
	For Each elm In objIE.Document.getElementsByTagName("meta")
		If elm.name = "description" then
			WScript.Echo "URL: " & url
			WScript.Echo "Title: " & objIE.Document.Title
			WScript.Echo "description: " & elm.Content
		End If
	Next
	For Each elm In objIE.Document.getElementsByTagName("a")
		If instr(1, elm.href, url) > 0 then
			Wscript.sleep 2000
			'WScript.Echo elm.href
		End If
	Next
	objIE.Quit
	Set objIE = Nothing
End Sub

Sub crawl(url)
	Dim ws
	Set ws = WScript.CreateObject("WScript.Shell")
	Dim objIE
	Set objIE = CreateObject("InternetExplorer.Application")
	objIE.Visible = True
	objIE.Navigate url
	ws.AppActivate("Internet Explorer")
	Do While objIE.ReadyState <> 4 Or objIE.Busy = True
	    WScript.Sleep 100
	Loop
	For Each elm In objIE.Document.getElementsByTagName("meta")
		If elm.name = "description" then
			WScript.Echo "URL: " & url
			WScript.Echo "Title: " & objIE.Document.Title
			WScript.Echo "description: " & elm.Content
		End If
	Next
	For Each elm In objIE.Document.getElementsByTagName("a")
		If instr(1, elm.href, url) > 0 then
			Wscript.sleep 2000
			WScript.Echo elm.href
			crawl2(elm.href)
		End If
	Next
	objIE.Quit
	Set objIE = Nothing
End Sub

Dim url
url = "https://auctions.yahoo.co.jp"
crawl(url)





以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?