質問編集履歴
1
コードを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,6 +42,112 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
+
### 追加したコード(build.gradle)
|
46
|
+
|
47
|
+
```Java
|
48
|
+
|
49
|
+
package com.example.cnn;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
import android.os.Bundle;
|
54
|
+
|
55
|
+
import android.widget.TextView;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
import androidx.appcompat.app.AppCompatActivity;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
import org.openqa.selenium.By;
|
64
|
+
|
65
|
+
import org.openqa.selenium.WebDriver;
|
66
|
+
|
67
|
+
import org.openqa.selenium.WebElement;
|
68
|
+
|
69
|
+
import org.openqa.selenium.chrome.ChromeDriver;
|
70
|
+
|
71
|
+
import org.openqa.selenium.chrome.ChromeOptions;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
import java.util.ArrayList;
|
76
|
+
|
77
|
+
import java.util.List;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
public class MainActivity extends AppCompatActivity {
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
@Override
|
86
|
+
|
87
|
+
protected void onCreate(Bundle savedInstanceState) {
|
88
|
+
|
89
|
+
super.onCreate(savedInstanceState);
|
90
|
+
|
91
|
+
setContentView(R.layout.activity_main);
|
92
|
+
|
93
|
+
TextView textView = findViewById(R.id.text_view);
|
94
|
+
|
95
|
+
final String PATH = "C:\Users\Myname\Desktop\chromedriver_android\chromedriver.exe";
|
96
|
+
|
97
|
+
System.setProperty("webdriver.chrome.driver", PATH);
|
98
|
+
|
99
|
+
ChromeOptions options = new ChromeOptions();
|
100
|
+
|
101
|
+
WebDriver driver = new ChromeDriver(options);
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
final String URL = "https:/***";
|
106
|
+
|
107
|
+
driver.get(URL);
|
108
|
+
|
109
|
+
List<WebElement> elements = driver.findElements(By.className("cd__headline"));
|
110
|
+
|
111
|
+
List<String> list = new ArrayList<>();
|
112
|
+
|
113
|
+
for (WebElement element : elements) {
|
114
|
+
|
115
|
+
WebElement aTag = element.findElement(By.tagName("a"));
|
116
|
+
|
117
|
+
if(aTag.getAttribute("href").contains("index.html")) {
|
118
|
+
|
119
|
+
list.add(aTag.getAttribute("href"));
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
driver.get(list.get(6));
|
126
|
+
|
127
|
+
List<WebElement> elements2 = driver.findElements(By.className("zn-body__paragraph"));
|
128
|
+
|
129
|
+
for (WebElement element : elements2) {
|
130
|
+
|
131
|
+
textView.setText(element.getText());
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
}
|
150
|
+
|
45
151
|
### その他
|
46
152
|
|
47
153
|
chromedriverをwindows版のものを使用しているのがうまくいかない原因かなと思っています。(検索しましたが、chromedriverのandroid版のものは見つけることができませんでした)
|