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

回答編集履歴

3

fix

2017/07/07 02:35

投稿

mattn
mattn

スコア5030

answer CHANGED
@@ -1,6 +1,14 @@
1
+ 一括で取りたい場合
2
+
1
3
  ```vbs
2
4
  Set doc = IE.Document
3
5
  Set names = doc.getElementsByClassName("Name")
6
+ WScript.Echo names(0).TextContent
7
+ ```
8
+
9
+ ```vbs
10
+ Set doc = IE.Document
11
+ Set names = doc.getElementsByClassName("Name")
4
12
  For Each a In names(0).Children(0).Children
5
13
  If a.NodeName = "P" Then
6
14
  WScript.Echo a.TextContent

2

fix

2017/07/07 02:35

投稿

mattn
mattn

スコア5030

answer CHANGED
@@ -1,23 +1,6 @@
1
1
  ```vbs
2
2
  Set doc = IE.Document
3
3
  Set names = doc.getElementsByClassName("Name")
4
- WScript.Echo names(0).TextContent
5
- ```
6
-
7
- テキストだけで良いなら TextContent で取れると思います。個別に取りたい場合は以下。
8
-
9
- ```vbs
10
- Set IE = CreateObject("InternetExplorer.Application")
11
-
12
- IE.Visible = True
13
- IE.Navigate "http://127.0.0.1:5000/"
14
-
15
- Do While IE.Busy Or IE.ReadyState <> 4
16
- WScript.Sleep(1)
17
- Loop
18
-
19
- Set doc = IE.Document
20
- Set names = doc.getElementsByClassName("Name")
21
4
  For Each a In names(0).Children(0).Children
22
5
  If a.NodeName = "P" Then
23
6
  WScript.Echo a.TextContent

1

fix

2017/07/07 02:34

投稿

mattn
mattn

スコア5030

answer CHANGED
@@ -4,4 +4,25 @@
4
4
  WScript.Echo names(0).TextContent
5
5
  ```
6
6
 
7
- テキストだけで良いなら TextContent で取れると思います。
7
+ テキストだけで良いなら TextContent で取れると思います。個別に取りたい場合は以下。
8
+
9
+ ```vbs
10
+ Set IE = CreateObject("InternetExplorer.Application")
11
+
12
+ IE.Visible = True
13
+ IE.Navigate "http://127.0.0.1:5000/"
14
+
15
+ Do While IE.Busy Or IE.ReadyState <> 4
16
+ WScript.Sleep(1)
17
+ Loop
18
+
19
+ Set doc = IE.Document
20
+ Set names = doc.getElementsByClassName("Name")
21
+ For Each a In names(0).Children(0).Children
22
+ If a.NodeName = "P" Then
23
+ WScript.Echo a.TextContent
24
+ End If
25
+ Next
26
+ ```
27
+
28
+ `.Document.getElementsByName` で取れますが、HTML 構造によっては期待した通りに取れないのであえて Children 使っています。