質問編集履歴
3
あ
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
```html
|
10
10
|
|
11
11
|
driver = webdriver.Chrome(executable_path=DRIVER_PATH, chrome_options=options)
|
12
12
|
|
@@ -57,3 +57,5 @@
|
|
57
57
|
else:
|
58
58
|
|
59
59
|
driver.close()
|
60
|
+
|
61
|
+
```
|
2
見にくかったので変えました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,66 +7,6 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
|
10
|
-
|
11
|
-
import os
|
12
|
-
|
13
|
-
import time
|
14
|
-
|
15
|
-
import random
|
16
|
-
|
17
|
-
import sys
|
18
|
-
|
19
|
-
from selenium import webdriver
|
20
|
-
|
21
|
-
from selenium.webdriver.common.keys import Keys
|
22
|
-
|
23
|
-
from selenium.webdriver.support.ui import WebDriverWait
|
24
|
-
|
25
|
-
from selenium.webdriver.common.by import By
|
26
|
-
|
27
|
-
# coding:utf-8
|
28
|
-
|
29
|
-
from selenium.webdriver.chrome.options import Options
|
30
|
-
|
31
|
-
from selenium.webdriver.support.select import Select
|
32
|
-
|
33
|
-
from selenium.webdriver.common.alert import Alert
|
34
|
-
|
35
|
-
from selenium.webdriver.support import expected_conditions as EC
|
36
|
-
|
37
|
-
from selenium.common.exceptions import TimeoutException
|
38
|
-
|
39
|
-
import chromedriver_binary
|
40
|
-
|
41
|
-
import time
|
42
|
-
|
43
|
-
from selenium.webdriver.common.action_chains import ActionChains
|
44
|
-
|
45
|
-
# Seleniumをあらゆる環境で起動させるChromeオプション
|
46
|
-
|
47
|
-
options = Options()
|
48
|
-
|
49
|
-
options.add_argument('--disable-gpu');
|
50
|
-
|
51
|
-
options.add_argument('--disable-extensions');
|
52
|
-
|
53
|
-
options.add_argument('--proxy-server="direct://"');
|
54
|
-
|
55
|
-
options.add_argument('--proxy-bypass-list=*');
|
56
|
-
|
57
|
-
options.add_argument('--start-maximized');
|
58
|
-
|
59
|
-
# options.add_argument('--headless'); # ※ヘッドレスモードを使用する場合、コメントアウトを外す
|
60
|
-
|
61
|
-
DRIVER_PATH = 'C:\webdriver\chromedriver\chromedriver.exe'
|
62
|
-
|
63
|
-
# Userプロファイルを読み込み
|
64
|
-
|
65
|
-
# PROFILE_PATH = 'C:\Users\__USER__\AppData\Local\Google\Chrome\User Data'
|
66
|
-
|
67
|
-
# options.add_argument("user-data-dir=PROFILE_PATH");
|
68
|
-
|
69
|
-
# ブラウザを開く。
|
70
10
|
|
71
11
|
driver = webdriver.Chrome(executable_path=DRIVER_PATH, chrome_options=options)
|
72
12
|
|
1
whileを回してます。
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,6 +8,112 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
import os
|
12
12
|
|
13
|
+
import time
|
14
|
+
|
15
|
+
import random
|
16
|
+
|
17
|
+
import sys
|
18
|
+
|
19
|
+
from selenium import webdriver
|
20
|
+
|
21
|
+
from selenium.webdriver.common.keys import Keys
|
22
|
+
|
23
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
24
|
+
|
25
|
+
from selenium.webdriver.common.by import By
|
26
|
+
|
27
|
+
# coding:utf-8
|
28
|
+
|
29
|
+
from selenium.webdriver.chrome.options import Options
|
30
|
+
|
31
|
+
from selenium.webdriver.support.select import Select
|
32
|
+
|
33
|
+
from selenium.webdriver.common.alert import Alert
|
34
|
+
|
35
|
+
from selenium.webdriver.support import expected_conditions as EC
|
36
|
+
|
37
|
+
from selenium.common.exceptions import TimeoutException
|
38
|
+
|
39
|
+
import chromedriver_binary
|
40
|
+
|
41
|
+
import time
|
42
|
+
|
43
|
+
from selenium.webdriver.common.action_chains import ActionChains
|
44
|
+
|
45
|
+
# Seleniumをあらゆる環境で起動させるChromeオプション
|
46
|
+
|
47
|
+
options = Options()
|
48
|
+
|
49
|
+
options.add_argument('--disable-gpu');
|
50
|
+
|
51
|
+
options.add_argument('--disable-extensions');
|
52
|
+
|
53
|
+
options.add_argument('--proxy-server="direct://"');
|
54
|
+
|
55
|
+
options.add_argument('--proxy-bypass-list=*');
|
56
|
+
|
57
|
+
options.add_argument('--start-maximized');
|
58
|
+
|
59
|
+
# options.add_argument('--headless'); # ※ヘッドレスモードを使用する場合、コメントアウトを外す
|
60
|
+
|
61
|
+
DRIVER_PATH = 'C:\webdriver\chromedriver\chromedriver.exe'
|
62
|
+
|
63
|
+
# Userプロファイルを読み込み
|
64
|
+
|
65
|
+
# PROFILE_PATH = 'C:\Users\__USER__\AppData\Local\Google\Chrome\User Data'
|
66
|
+
|
67
|
+
# options.add_argument("user-data-dir=PROFILE_PATH");
|
68
|
+
|
69
|
+
# ブラウザを開く。
|
70
|
+
|
71
|
+
driver = webdriver.Chrome(executable_path=DRIVER_PATH, chrome_options=options)
|
72
|
+
|
73
|
+
driver.implicitly_wait(3)
|
74
|
+
|
75
|
+
driver.get("~~URL~~")
|
76
|
+
|
77
|
+
#
|
78
|
+
|
79
|
+
I=1
|
80
|
+
|
81
|
+
II=1
|
82
|
+
|
83
|
+
while II < 1000:
|
84
|
+
|
85
|
+
if I == 21:
|
86
|
+
|
87
|
+
II=II+2
|
88
|
+
|
89
|
+
I=1
|
90
|
+
|
91
|
+
else:
|
92
|
+
|
93
|
+
print(str(I))
|
94
|
+
|
95
|
+
v = dict(first="I", last="II")
|
96
|
+
|
13
|
-
selector = "#layout-%(first) > div > a:
|
97
|
+
selector = "#layout-%(first)s > div > div > a:nth-child(%(last)s)" % v
|
98
|
+
|
99
|
+
if len(driver.find_elements_by_css_selector(selector)) == 0:
|
100
|
+
|
101
|
+
driver.find_element_by_tag_name('body').send_keys(Keys.END)
|
102
|
+
|
103
|
+
else:
|
104
|
+
|
105
|
+
element = driver.find_element_by_css_selector(selector)
|
106
|
+
|
107
|
+
element.click()
|
108
|
+
|
109
|
+
time.sleep(1)
|
110
|
+
|
111
|
+
I=I+1
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
else:
|
118
|
+
|
119
|
+
driver.close()
|