
'UserFormモジュール
Option Explicit
Const READYSTATE_COMPLETE As Long = 4
Const MX As Long = 20 'WebBrowser数
Const CX As Long = 8 'データ取得用配列の列サイズ
'エラーor読み込みor位置 判断keyword
Const keyW1 = "非公開に設定されています"
Const keyW2 = "404 Not Found"
Const keyW3 = "<DIV class=ok_lq_qa_list_r>"
Const keyW4 = "<DIV id=paginater_history_answers>"
'RegExp用pattern
Const PTNd = "<SPAN id=answer_count>(\d+)</SPAN>"
Const PTN0 = "質問者:| -日付:| -回答数:|カテゴリ:|" _
& "<STRONG>画像</STRONG>|<STRONG>絵</STRONG>"
Const PTN1 = ">([^<]+)<"
Const PTN2 = "<P class=qat><A href=""([^<]+)"">"
Private escFlg As Boolean 'Cancel用フラグ
Private reg As Object 'VBScript.RegExp
Private buf() As String 'data取得用
'-------------------------------------------------
Private Sub main()
Dim sURL(0 To 5) As String 'URL文字列
Dim v(0 To 50, 0 To CX) As String '書き出し用配列
Dim wFlg(1 To MX) As Boolean 'WebBrowser稼動判定
Dim dFlg As Boolean 'LoopExit判定用
Dim x As Object 'HTMLelement
Dim mc As Object 'RegExp.Match
Dim ret As String 'innerHTMLチェック用
Dim dat() As String 'data取得用
Dim i As Long 'カウンタ
Dim j As Long 'カウンタ
Dim k As Long 'カウンタ
Dim p As Long 'InStr結果。文字検出位置
Dim cnt As Long 'countup用
Dim pg As Long 'Page数
Dim ac As Long '回答数
Dim wx As Long 'Loop設定用
Dim timeout As Single 'タイムアウト設定
Dim uid, page
uid = Application.InputBox("userID", , 1037781, Type:=1)
If VarType(uid) = vbBoolean Then Exit Sub
timeout = Timer + 100
Dim t As Single
t = Timer
'sURL(0) = "
http://c.oshiete.goo.ne.jp"
sURL(0) = "
http://bekkoame.okwave.jp"
sURL(1) = "/profile/answer/history/u"
sURL(2) = CStr(uid)
sURL(3) = ".html?page="
sURL(4) = 1
sURL(5) = "#tabs"
Set reg = CreateObject("VBScript.RegExp")
reg.Global = True
reg.Pattern = PTNd
'■
With Me.WebBrowser1
.Navigate Join(sURL, "")
'待ち
While .Busy Or (.ReadyState <> READYSTATE_COMPLETE)
DoEvents
Wend
With .Document
'待ち と回答数取得
While (Not dFlg)
DoEvents
ret = .body.innerhtml
If InStr(ret, keyW1) > 0 Then GoTo exitLine
If InStr(ret, keyW2) > 0 Then GoTo exitLine
Set mc = reg.Execute(ret)
dFlg = (mc.Count > 0)
Wend
'ユーザー名
For Each x In .getElementsByTagName("h3")
v(cnt, 0) = x.innertext
Exit For
Next
'UserForm1.Tagにセットした時だけ有効
If Me.Tag = "a" Then
'登録日と自己紹介
cnt = 1
For Each x In .getElementsByTagName("p")
If cnt = 2 Then Exit For
If x.innertext Like "登録日:*" Then
v(cnt, 0) = x.innertext
cnt = cnt + 1
End If
Next
v(cnt, 0) = x.innertext
'プロフィール。tableタグLoop
For Each x In .getElementsByTagName("table")
If x.classname = "ok_mypage_userdata" Or _
x.classname = "ok_mypage_userprofile" Then
For i = 0 To x.Rows.length - 1
cnt = cnt + 1
For j = 0 To x.Rows(i).Cells.length - 1
v(cnt, j) = x.Rows(i).Cells(j).innertext
Next
Next
End If
Next
End If
End With
End With
'■以上WebBrowser1だけの処理
'-------------------------------------------------
'暫定版2へ