質問編集履歴
1
コードを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,6 +20,59 @@
|
|
20
20
|
}
|
21
21
|
```
|
22
22
|
|
23
|
+
### 追加したコード(build.gradle)
|
24
|
+
```Java
|
25
|
+
package com.example.cnn;
|
26
|
+
|
27
|
+
import android.os.Bundle;
|
28
|
+
import android.widget.TextView;
|
29
|
+
|
30
|
+
import androidx.appcompat.app.AppCompatActivity;
|
31
|
+
|
32
|
+
import org.openqa.selenium.By;
|
33
|
+
import org.openqa.selenium.WebDriver;
|
34
|
+
import org.openqa.selenium.WebElement;
|
35
|
+
import org.openqa.selenium.chrome.ChromeDriver;
|
36
|
+
import org.openqa.selenium.chrome.ChromeOptions;
|
37
|
+
|
38
|
+
import java.util.ArrayList;
|
39
|
+
import java.util.List;
|
40
|
+
|
41
|
+
public class MainActivity extends AppCompatActivity {
|
42
|
+
|
43
|
+
@Override
|
44
|
+
protected void onCreate(Bundle savedInstanceState) {
|
45
|
+
super.onCreate(savedInstanceState);
|
46
|
+
setContentView(R.layout.activity_main);
|
47
|
+
TextView textView = findViewById(R.id.text_view);
|
48
|
+
final String PATH = "C:\Users\Myname\Desktop\chromedriver_android\chromedriver.exe";
|
49
|
+
System.setProperty("webdriver.chrome.driver", PATH);
|
50
|
+
ChromeOptions options = new ChromeOptions();
|
51
|
+
WebDriver driver = new ChromeDriver(options);
|
52
|
+
|
53
|
+
final String URL = "https:/***";
|
54
|
+
driver.get(URL);
|
55
|
+
List<WebElement> elements = driver.findElements(By.className("cd__headline"));
|
56
|
+
List<String> list = new ArrayList<>();
|
57
|
+
for (WebElement element : elements) {
|
58
|
+
WebElement aTag = element.findElement(By.tagName("a"));
|
59
|
+
if(aTag.getAttribute("href").contains("index.html")) {
|
60
|
+
list.add(aTag.getAttribute("href"));
|
61
|
+
}
|
62
|
+
}
|
63
|
+
driver.get(list.get(6));
|
64
|
+
List<WebElement> elements2 = driver.findElements(By.className("zn-body__paragraph"));
|
65
|
+
for (WebElement element : elements2) {
|
66
|
+
textView.setText(element.getText());
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
}
|
23
76
|
### その他
|
24
77
|
chromedriverをwindows版のものを使用しているのがうまくいかない原因かなと思っています。(検索しましたが、chromedriverのandroid版のものは見つけることができませんでした)
|
25
78
|
そもそもandroidでseleniumを動かすというのが無理なのでしょうか?
|