teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

コードの修正

2020/06/09 09:00

投稿

hirokin92
hirokin92

スコア3

title CHANGED
File without changes
body CHANGED
@@ -116,7 +116,7 @@
116
116
  '------------------------------------
117
117
  Dim access As Object
118
118
  For Each access In WebIE.document.getElementsByTagName("a") '①FOR EACH でINPUTをすべて抜き出す。
119
- If access.innerText = "アクセス" Or access.innerText = "会社概要" Or access.innerText = "会社概要・アクセス" Then
119
+ If access.innerText = "" Or access.innerText = "テスト1" Or access.innerText = "ト2" Then
120
120
  While WebIE.Busy Or WebIE.readyState <> READYSTATE_COMPLETE
121
121
  DoEvents
122
122
  Wend

1

コードを全体に修正しました。

2020/06/09 09:00

投稿

hirokin92
hirokin92

スコア3

title CHANGED
File without changes
body CHANGED
@@ -15,16 +15,128 @@
15
15
 
16
16
  ------
17
17
  ■作成したコード
18
- 1.Dim juusyo As Object
19
- 2.Dim cntn As Long
20
- 3.cntn = 5
18
+ Sub test()
21
- 4.For Each juusyo In webIE.document.getElementsByTagName("p")
22
- 5.If InStr(juusyo.innerText, "東京都") > 0 Then
23
- 6.MsgBox juusyo.innerText
24
- 7.Cells(cntn, 1).Value = juusyo.innerText
25
- 8.End If
26
- 9.Next
27
19
 
20
+ Dim searchx As String
21
+ Dim searchy As String
22
+ Dim all As String
23
+ Dim box() As String
28
24
 
25
+ Dim WebIE As InternetExplorer
26
+
27
+ '------------------------------------
28
+ '★セルの文字取得
29
+
30
+ searchx = Cells(1, 1)
31
+ searchy = Mid(Cells(1, 5), InStr(Cells(1, 5), "@") + 1, 20)
32
+ all = searchx + " " + searchy
33
+ '------------------------------------
34
+
35
+ '------------------------------------
36
+ '★変数webIEを使用してIE起動
37
+
38
+ Set WebIE = New InternetExplorer
39
+
40
+ WebIE.Visible = True
41
+ WebIE.Navigate "https://www.google.com/?hl=ja"
42
+ '------------------------------------
43
+
44
+ '------------------------------------
29
- 「4.」処理が完了するまで5以降の処理は止めたです。
45
+ '★IEリロード完了まで処理をしな
46
+
47
+ While WebIE.Busy Or WebIE.readyState <> READYSTATE_COMPLETE
48
+ DoEvents
49
+ Wend
50
+ '------------------------------------
51
+
52
+ On Error Resume Next '値がないとエラーが出るので、エラー回避用
53
+
54
+ '------------------------------------
55
+ '★値をWebで入力
56
+ Dim A As Object
57
+ For Each A In WebIE.document.getElementsByTagName("INPUT") '①FOR EACH でINPUTをすべて抜き出す。
58
+ If A.name = "q" Then A.Value = all
59
+ Next
60
+ '------------------------------------
61
+
62
+
63
+ '------------------------------------
64
+ '★検索ボタンをクリック
65
+ Dim b As Object
66
+ For Each b In WebIE.document.getElementsByTagName("INPUT") '①FOR EACH でINPUTをすべて抜き出す。
67
+ If A.name = "btnk" Then b.Click
68
+ While WebIE.Busy Or WebIE.readyState <> READYSTATE_COMPLETE
69
+ DoEvents
70
+ Wend
71
+ Next
72
+ '------------------------------------
73
+
74
+ '-------------------------------------
75
+ '★指定したURLのみ取得
30
- よろしくお願いいたします。
76
+ Dim i As Long
77
+ Dim boxi As Long
78
+ ReDim box(boxi)
79
+ i = 5
80
+ boxi = 0
81
+
82
+ Dim htmlDoc As HTMLDocument
83
+ Set htmlDoc = WebIE.document
84
+ Dim anchor As HTMLAnchorElement
85
+
86
+ For Each anchor In htmlDoc.Links
87
+
88
+ If InStr(anchor, searchy) <> 0 And InStr(anchor, "google.com") = 0 Then
89
+ box(boxi) = anchor
90
+ 'Cells(i, 1).Value = anchor
91
+ Else
92
+ boxi = boxi - 1
93
+ i = i - 1
94
+ End If
95
+
96
+
97
+ i = i + 1
98
+ boxi = boxi + 1
99
+ Next anchor
100
+
101
+ '-------------------------------------
102
+ WebIE.Quit
103
+
104
+ Set WebIE = New InternetExplorer
105
+ WebIE.Visible = True
106
+ WebIE.Navigate2 box(0)
107
+ '------------------------------------
108
+
109
+ '------------------------------------
110
+ '★IEのリロード完了まで処理をしない
111
+
112
+ While WebIE.Busy Or WebIE.readyState <> READYSTATE_COMPLETE
113
+ DoEvents
114
+ Wend
115
+
116
+ '------------------------------------
117
+ Dim access As Object
118
+ For Each access In WebIE.document.getElementsByTagName("a") '①FOR EACH でINPUTをすべて抜き出す。
119
+ If access.innerText = "アクセス" Or access.innerText = "会社概要" Or access.innerText = "会社概要・アクセス" Then
120
+ While WebIE.Busy Or WebIE.readyState <> READYSTATE_COMPLETE
121
+ DoEvents
122
+ Wend
123
+ access.Click
124
+ Exit For
125
+ End If
126
+ Next
127
+
128
+ Dim juusyo As Object
129
+ Dim cntn As Long
130
+ Dim change As String
131
+
132
+ cntn = 5
133
+ For Each juusyo In WebIE.document.getElementsByTagName("p")
134
+ If InStr(juusyo.innerText, "東京都") > 0 Then
135
+ Cells(cntn, 1).Value = juusyo.innerText
136
+ Else
137
+ End If
138
+
139
+ Next
140
+
141
+
142
+ End Sub