回答編集履歴
3
typo
test
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
def condition(driver) -> bool:
|
30
30
|
|
31
|
-
look_for = ['google', 'teratail', 'example']
|
31
|
+
look_for = ['google', 'treratail', 'example']
|
32
32
|
|
33
33
|
url = driver.current_url
|
34
34
|
|
@@ -62,13 +62,13 @@
|
|
62
62
|
|
63
63
|
WebDriverWait(driver, timeout=10).until(condition)
|
64
64
|
|
65
|
-
"done:{}".format(driver.current_url)
|
65
|
+
print("done:{}".format(driver.current_url))
|
66
66
|
|
67
67
|
except TimeoutException as ex:
|
68
68
|
|
69
69
|
print("#" * 80)
|
70
70
|
|
71
|
-
print(ex
|
71
|
+
print(ex)
|
72
72
|
|
73
73
|
finally:
|
74
74
|
|
2
refactoring
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
from selenium import webdriver
|
10
10
|
|
11
|
-
from selenium.
|
11
|
+
from selenium.common.exceptions import TimeoutException
|
12
12
|
|
13
13
|
from selenium.webdriver.support.ui import WebDriverWait
|
14
14
|
|
@@ -26,19 +26,17 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
-
def condition(driver):
|
29
|
+
def condition(driver) -> bool:
|
30
30
|
|
31
31
|
look_for = ['google', 'teratail', 'example']
|
32
32
|
|
33
33
|
url = driver.current_url
|
34
34
|
|
35
|
-
for s in look_for:
|
35
|
+
if any(url.find(s) != -1 for s in look_for):
|
36
36
|
|
37
|
-
if
|
37
|
+
print("match:{}".format(url))
|
38
38
|
|
39
|
-
print("match:{}".format(s))
|
40
|
-
|
41
|
-
|
39
|
+
return True
|
42
40
|
|
43
41
|
|
44
42
|
|
@@ -48,7 +46,7 @@
|
|
48
46
|
|
49
47
|
|
50
48
|
|
51
|
-
def main() ->None:
|
49
|
+
def main() -> None:
|
52
50
|
|
53
51
|
driver = webdriver.Chrome()
|
54
52
|
|
@@ -56,13 +54,21 @@
|
|
56
54
|
|
57
55
|
print("req:{}".format(url))
|
58
56
|
|
59
|
-
driver.get(url)
|
60
|
-
|
61
57
|
try:
|
62
58
|
|
63
|
-
|
59
|
+
driver.get(url)
|
64
60
|
|
61
|
+
try:
|
62
|
+
|
63
|
+
WebDriverWait(driver, timeout=10).until(condition)
|
64
|
+
|
65
|
+
"done:{}".format(driver.current_url)
|
66
|
+
|
67
|
+
except TimeoutException as ex:
|
68
|
+
|
69
|
+
print("#" * 80)
|
70
|
+
|
65
|
-
print(
|
71
|
+
print(ex.stacktrace)
|
66
72
|
|
67
73
|
finally:
|
68
74
|
|
1
conditionの判定を修正
test
CHANGED
@@ -11,8 +11,6 @@
|
|
11
11
|
from selenium.webdriver.common.by import By
|
12
12
|
|
13
13
|
from selenium.webdriver.support.ui import WebDriverWait
|
14
|
-
|
15
|
-
from selenium.webdriver.support import expected_conditions as EC
|
16
14
|
|
17
15
|
|
18
16
|
|
@@ -30,11 +28,15 @@
|
|
30
28
|
|
31
29
|
def condition(driver):
|
32
30
|
|
33
|
-
|
31
|
+
look_for = ['google', 'teratail', 'example']
|
34
32
|
|
35
|
-
|
33
|
+
url = driver.current_url
|
36
34
|
|
35
|
+
for s in look_for:
|
36
|
+
|
37
|
-
if
|
37
|
+
if url.find(s) != -1:
|
38
|
+
|
39
|
+
print("match:{}".format(s))
|
38
40
|
|
39
41
|
return True
|
40
42
|
|
@@ -50,7 +52,11 @@
|
|
50
52
|
|
51
53
|
driver = webdriver.Chrome()
|
52
54
|
|
55
|
+
url = get_url()
|
56
|
+
|
57
|
+
print("req:{}".format(url))
|
58
|
+
|
53
|
-
driver.get(
|
59
|
+
driver.get(url)
|
54
60
|
|
55
61
|
try:
|
56
62
|
|
@@ -70,6 +76,8 @@
|
|
70
76
|
|
71
77
|
main()
|
72
78
|
|
79
|
+
|
80
|
+
|
73
81
|
```
|
74
82
|
|
75
83
|
|