'CYTOLOGY2 HomepageBuilder作成ページ検索 20130226 '--------------------------------------------------------------- 'Copyright(C) 2013 ao-system エーオーシステム 'licensed under the LGPL 'ライセンスはLGPLに準じたものになります。詳しくは下記サイトを参照下さい。 'https://ao-system.net/cytology2/ 'LGPLに準じ、この著作権表示は消去できません。 '--------------------------------------------------------------- ' 'HomePageBuilderで作成されたサイトを検索。 'Yahooの検索結果から、METAタグGENERATORに Homepage Builder が含まれるサイトをリストアップします。 '結果表示後に新規Excelファイルへ書き出す事が可能です。 ' '--------------------------------------------------------------- Imports System.Drawing Imports System.Windows.Forms Public Class AddIn Private Const APPNAME As String = "HomepageBuilder作成ページ検索" Private tabb As TabBrowser Private std As Std Private stdf As StdFunc Private ddLabelNow As ToolStripLabel Private urlList(1000) As String Private urlListIndex As Integer Private findList(1000) As String Private findListIndex As Integer Private findTitle(1000) As String Private busyNavigate As Boolean Private searchWord As String Private searchFrom As Integer Private searchTo As Integer Public Sub New() tabb = New TabBrowser() std = New Std() stdf = New StdFunc() End Sub Public Sub AddIn_Load() startMessage() End Sub Public Sub AddIn_Stop() std.AddInMenuRemove() End Sub Public Sub AddIn_Start() searchWord = tabb.WebBrowser.Document.GetElementById("inputsearchword").InnerHtml searchFrom = stdf.IntVal(tabb.WebBrowser.Document.GetElementById("inputsearchfrom").InnerHtml) searchTo = stdf.IntVal(tabb.WebBrowser.Document.GetElementById("inputsearchto").InnerHtml) ddButtonInitial01() ysearch() urlMessage() homepagebuilderSearch() findMessage() excelOut() std.ExitAddIn() End Sub Private Sub info(ByVal str As String, ByVal c As Color) If std.StopFlag Then Exit Sub ddLabelNow.Text = str ddLabelNow.ForeColor = c Application.DoEvents() End Sub Private Sub ddButtonInitial01() ddLabelNow = New ToolStripLabel("停止中") ddLabelNow.ForeColor = Color.Black std.AddInMenuAddOnce(ddLabelNow) End Sub Private Sub startMessage() tabb.TabText = APPNAME Dim str As String = "" str &= "" str &= "" str &= "" str &= "" str &= "HomePageBuilderで作成されたサイトを検索" str &= "" str &= "" str &= "" str &= "

HomePageBuilderで作成されたサイトを検索

" str &= "
Yahooの検索結果から、METAタグGENERATORに Homepage Builder が含まれるサイトをリストアップします。
" str &= "結果表示後に新規Excelファイルへ書き出す事が可能です。" str &= "
" str &= "
" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "" str &= "
検索語句検索開始ページ検索終了ページ
Yahoo検索ワード
例) 浜松
例) 浜松 工業
例) 東京 不動産
ページ番号
(1ページ100件)
1から10の整数
ページ番号
(1ページ100件)
1から10の整数
 
" str &= "
" str &= "" str &= "
" str &= "
まれに勝手に別窓を開くサイトが有りますので、メニューの「FILE」-「設定」のリンククリック時の新規ウインドウ処理を「全てIE起動」または「全て指定ブラウザ起動」にすることをお勧めします。
" str &= "インターネットオプションの「詳細設定」でマルチメディア項目の「画像を表示しない」にすると速度が速くなります。
" str &= "初めて使う場合は1ページ程の少ない指定で動作をご確認ください。" str &= "
" str &= "" str &= "" str &= "" tabb.WebBrowser.DocumentText = str End Sub Private Sub ysearch() urlListIndex = 0 For i As Integer = searchFrom - 1 To searchTo - 1 Step 1 busyNavigate = True tabb.Navigate("http://search.yahoo.co.jp/search?p=" & System.Uri.EscapeUriString(searchWord) & "&ei=UTF-8&n=100&b=" & (i * 100 + 1).ToString) tabb.DocumentCompletedEventAdd(AddressOf ysearch2) stdf.WaitMilliSec(500) For i2 As Integer = 0 To 30 Step 1 If busyNavigate = False Then Exit For End If stdf.WaitMilliSec(1000) Next If std.StopFlag Then Exit For Next End Sub Private Sub ysearch2(ByVal sender As Object, ByVal e As System.EventArgs) tabb.DocumentCompletedEventRemove(AddressOf ysearch2) Dim elems As HtmlElementCollection = tabb.WebBrowser.Document.GetElementsByTagName("H3") For Each elm As HtmlElement In elems If elm.InnerHtml.StartsWith(" 0 Then Exit Sub End If Next For i As Integer = 0 To urlListIndex - 1 Step 1 If urlList(i) = url Then Exit Sub End If Next urlList(urlListIndex) = url urlListIndex += 1 End Sub Private Sub urlMessage() tabb.TabText = APPNAME Dim str As String = "" str &= "URL抽出結果" str &= "" str &= "

URL抽出結果

" For i As Integer = 0 To urlListIndex - 1 Step 1 str &= urlList(i) & "
" Next str &= "" tabb.WebBrowser.DocumentText = str End Sub Private Sub homepagebuilderSearch() findListIndex = 0 For i As Integer = 0 To urlListIndex - 1 Step 1 info("Check: " & i.ToString & " / " & (urlListIndex - 1).ToString, Color.Blue) busyNavigate = True tabb.Navigate(urlList(i)) tabb.DocumentCompletedEventAdd(AddressOf homepagebuilderSearch2) stdf.WaitMilliSec(500) For i2 As Integer = 0 To 15 Step 1 If busyNavigate = False Then Exit For End If stdf.WaitMilliSec(1000) Next tabb.WebBrowser.DocumentText = "" If std.StopFlag Then Exit For Next End Sub Private Sub homepagebuilderSearch2(ByVal sender As Object, ByVal e As System.EventArgs) tabb.DocumentCompletedEventRemove(AddressOf homepagebuilderSearch2) Dim elems As HtmlElementCollection = tabb.WebBrowser.Document.GetElementsByTagName("META") Dim limitCount As Integer = 20 For Each elm As HtmlElement In elems If elm.GetAttribute("name") = "GENERATOR" AndAlso elm.GetAttribute("content").IndexOf("Homepage Builder") > 0 Then setFindList(tabb.WebBrowser.Url.ToString, tabb.WebBrowser.DocumentTitle) info("Find(" & findListIndex.ToString & "): " & tabb.WebBrowser.Url.ToString, Color.Blue) Exit For End If limitCount -= 1 If limitCount < 1 Then Exit For End If If std.StopFlag Then Exit For Next busyNavigate = False End Sub Private Sub setFindList(ByVal url As String, ByVal title As String) For i As Integer = 0 To findListIndex - 1 Step 1 If findList(i) = url Then Exit Sub End If Next findList(findListIndex) = url findTitle(findListIndex) = title findListIndex += 1 End Sub Private Sub findMessage() tabb.TabText = APPNAME Dim str As String = "" str &= "Homepage Builder検索結果" str &= "" str &= "

Homepage Builder検索結果

" For i As Integer = 0 To findListIndex - 1 Step 1 str &= findTitle(i) & "," & findList(i) & "
" Next str &= "" tabb.WebBrowser.DocumentText = str End Sub Private Sub excelOut() If MessageBox.Show("エクセルで出力しますか?", APPNAME, MessageBoxButtons.YesNo, MessageBoxIcon.Question) <> DialogResult.Yes Then Exit Sub End If Dim sfd As New SaveFileDialog() sfd.FileName = searchWord & ".xlsx" sfd.InitialDirectory = "C:\" sfd.Filter = "xlsx(*.xlsx)|*.xlsx|すべてのファイル(*.*)|*.*" sfd.FilterIndex = 1 sfd.Title = "保存先のファイルを選択してください" sfd.RestoreDirectory = True sfd.OverwritePrompt = True sfd.CheckPathExists = True Do While True If sfd.ShowDialog() = DialogResult.OK Then Exit Do End If If MessageBox.Show("エクセル出力を続行しますか? 続行の場合はYes 中止の場合はNo", APPNAME, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then Exit Sub End If Loop excelOutStart() Dim es As ExcelSheet = New ExcelSheet() es.SelectSheet(1) For i As Integer = 0 To findListIndex - 1 Step 1 es.RangeFormat(1, i + 1, 2, i + 1, "@") es.CellValue(1, i + 1, findTitle(i)) es.CellValue(2, i + 1, findList(i)) Next es.Save(sfd.FileName) es.Dispose() excelOutEnd() End Sub Private Sub excelOutStart() Dim str As String = "" str &= "Homepage Builder検索結果" str &= "" str &= "

Homepage Builder検索結果をエクセルファイルに出力しています。しばらくお待ちください...

" str &= "" tabb.WebBrowser.DocumentText = str Application.DoEvents() End Sub Private Sub excelOutEnd() Dim str As String = "" str &= "Homepage Builder検索結果" str &= "" str &= "

Homepage Builder検索結果をエクセルファイルに出力しました。全ての処理が終了しました。

" str &= "検索文字:" & searchWord & "
" str &= "検索範囲:" & searchFrom & " から " & searchTo & " まで。100サイト単位
" str &= "出力数:" & findListIndex.ToString & " 件
" str &= "終了時刻:" & System.DateTime.Now & "
" str &= "" tabb.WebBrowser.DocumentText = str Application.DoEvents() End Sub End Class