質問編集履歴
3
あ
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
selectorにIとIIという数字を文字列にして代入して出力したいのですが、うまくいきません。
|
|
3
3
|
よろしければ何が間違っているか教えていただければと思います。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```html
|
|
6
6
|
driver = webdriver.Chrome(executable_path=DRIVER_PATH, chrome_options=options)
|
|
7
7
|
driver.implicitly_wait(3)
|
|
8
8
|
driver.get("~~URL~~")
|
|
@@ -27,4 +27,5 @@
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
else:
|
|
30
|
-
driver.close()
|
|
30
|
+
driver.close()
|
|
31
|
+
```
|
2
見にくかったので変えました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -3,36 +3,6 @@
|
|
|
3
3
|
よろしければ何が間違っているか教えていただければと思います。
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import os
|
|
7
|
-
import time
|
|
8
|
-
import random
|
|
9
|
-
import sys
|
|
10
|
-
from selenium import webdriver
|
|
11
|
-
from selenium.webdriver.common.keys import Keys
|
|
12
|
-
from selenium.webdriver.support.ui import WebDriverWait
|
|
13
|
-
from selenium.webdriver.common.by import By
|
|
14
|
-
# coding:utf-8
|
|
15
|
-
from selenium.webdriver.chrome.options import Options
|
|
16
|
-
from selenium.webdriver.support.select import Select
|
|
17
|
-
from selenium.webdriver.common.alert import Alert
|
|
18
|
-
from selenium.webdriver.support import expected_conditions as EC
|
|
19
|
-
from selenium.common.exceptions import TimeoutException
|
|
20
|
-
import chromedriver_binary
|
|
21
|
-
import time
|
|
22
|
-
from selenium.webdriver.common.action_chains import ActionChains
|
|
23
|
-
# Seleniumをあらゆる環境で起動させるChromeオプション
|
|
24
|
-
options = Options()
|
|
25
|
-
options.add_argument('--disable-gpu');
|
|
26
|
-
options.add_argument('--disable-extensions');
|
|
27
|
-
options.add_argument('--proxy-server="direct://"');
|
|
28
|
-
options.add_argument('--proxy-bypass-list=*');
|
|
29
|
-
options.add_argument('--start-maximized');
|
|
30
|
-
# options.add_argument('--headless'); # ※ヘッドレスモードを使用する場合、コメントアウトを外す
|
|
31
|
-
DRIVER_PATH = 'C:\webdriver\chromedriver\chromedriver.exe'
|
|
32
|
-
# Userプロファイルを読み込み
|
|
33
|
-
# PROFILE_PATH = 'C:\Users\__USER__\AppData\Local\Google\Chrome\User Data'
|
|
34
|
-
# options.add_argument("user-data-dir=PROFILE_PATH");
|
|
35
|
-
# ブラウザを開く。
|
|
36
6
|
driver = webdriver.Chrome(executable_path=DRIVER_PATH, chrome_options=options)
|
|
37
7
|
driver.implicitly_wait(3)
|
|
38
8
|
driver.get("~~URL~~")
|
1
whileを回してます。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -3,5 +3,58 @@
|
|
|
3
3
|
よろしければ何が間違っているか教えていただければと思います。
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
import os
|
|
7
|
+
import time
|
|
8
|
+
import random
|
|
9
|
+
import sys
|
|
10
|
+
from selenium import webdriver
|
|
11
|
+
from selenium.webdriver.common.keys import Keys
|
|
12
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
13
|
+
from selenium.webdriver.common.by import By
|
|
14
|
+
# coding:utf-8
|
|
15
|
+
from selenium.webdriver.chrome.options import Options
|
|
16
|
+
from selenium.webdriver.support.select import Select
|
|
17
|
+
from selenium.webdriver.common.alert import Alert
|
|
18
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
19
|
+
from selenium.common.exceptions import TimeoutException
|
|
20
|
+
import chromedriver_binary
|
|
21
|
+
import time
|
|
22
|
+
from selenium.webdriver.common.action_chains import ActionChains
|
|
23
|
+
# Seleniumをあらゆる環境で起動させるChromeオプション
|
|
24
|
+
options = Options()
|
|
25
|
+
options.add_argument('--disable-gpu');
|
|
26
|
+
options.add_argument('--disable-extensions');
|
|
27
|
+
options.add_argument('--proxy-server="direct://"');
|
|
28
|
+
options.add_argument('--proxy-bypass-list=*');
|
|
29
|
+
options.add_argument('--start-maximized');
|
|
30
|
+
# options.add_argument('--headless'); # ※ヘッドレスモードを使用する場合、コメントアウトを外す
|
|
31
|
+
DRIVER_PATH = 'C:\webdriver\chromedriver\chromedriver.exe'
|
|
32
|
+
# Userプロファイルを読み込み
|
|
33
|
+
# PROFILE_PATH = 'C:\Users\__USER__\AppData\Local\Google\Chrome\User Data'
|
|
34
|
+
# options.add_argument("user-data-dir=PROFILE_PATH");
|
|
35
|
+
# ブラウザを開く。
|
|
36
|
+
driver = webdriver.Chrome(executable_path=DRIVER_PATH, chrome_options=options)
|
|
37
|
+
driver.implicitly_wait(3)
|
|
38
|
+
driver.get("~~URL~~")
|
|
39
|
+
#
|
|
40
|
+
I=1
|
|
41
|
+
II=1
|
|
42
|
+
while II < 1000:
|
|
43
|
+
if I == 21:
|
|
44
|
+
II=II+2
|
|
45
|
+
I=1
|
|
46
|
+
else:
|
|
47
|
+
print(str(I))
|
|
6
|
-
|
|
48
|
+
v = dict(first="I", last="II")
|
|
7
|
-
|
|
49
|
+
selector = "#layout-%(first)s > div > div > a:nth-child(%(last)s)" % v
|
|
50
|
+
if len(driver.find_elements_by_css_selector(selector)) == 0:
|
|
51
|
+
driver.find_element_by_tag_name('body').send_keys(Keys.END)
|
|
52
|
+
else:
|
|
53
|
+
element = driver.find_element_by_css_selector(selector)
|
|
54
|
+
element.click()
|
|
55
|
+
time.sleep(1)
|
|
56
|
+
I=I+1
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
else:
|
|
60
|
+
driver.close()
|