質問編集履歴
2
コード内容の詳細を記載した
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,9 +2,39 @@
|
|
2
2
|
以下のイメージでスクレイピングを実行した際のタイムアウト時の処理を書こうと考えています。
|
3
3
|
|
4
4
|
```python3
|
5
|
+
search = []
|
6
|
+
|
7
|
+
result = []
|
8
|
+
|
9
|
+
with open('IPlist.txt', encoding='utf-8') as f:
|
10
|
+
|
5
|
-
for
|
11
|
+
for rows in f:
|
12
|
+
row = rows.rstrip('\n\n')
|
13
|
+
search.append(row)
|
14
|
+
|
15
|
+
for ip in search:
|
16
|
+
#seleniumでブラックリスト検索画面に移行
|
17
|
+
driver.get('https://www.aguse.jp/')
|
18
|
+
sleep(1)
|
19
|
+
#検索欄を選択
|
20
|
+
id=driver.find_element_by_id('url')
|
21
|
+
#searchからipアドレスを一つずつ検索欄に入力する
|
22
|
+
id.send_keys(ip)
|
23
|
+
sleep(1)
|
24
|
+
|
25
|
+
#検索開始ボタンを押下する
|
26
|
+
driver.find_element_by_class_name('btn1').click()
|
27
|
+
element = WebDriverWait(driver, 60).until(
|
28
|
+
EC.presence_of_element_located((By.CLASS_NAME, "section-body"))
|
29
|
+
)
|
30
|
+
|
31
|
+
sleep(10)
|
32
|
+
|
33
|
+
source = driver.page_source
|
34
|
+
soup = BeautifulSoup(source, "html.parser")
|
35
|
+
|
6
|
-
if
|
36
|
+
if タイムアウトエラーが発生したことを示す:
|
7
|
-
|
37
|
+
result.append('timeout')
|
8
38
|
continue
|
9
39
|
```
|
10
40
|
#質問内容
|
1
タイムアウト時のエラー内容を追記
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
python3でのスクレイピングのタイムアウトエラー表現
|
1
|
+
python3でのスクレイピングのタイムアウトエラー表現方法を教えてください
|
body
CHANGED
@@ -11,4 +11,13 @@
|
|
11
11
|
上記のコード内の「タイムアウトエラーが発生したことを示す」という部分についてですが、
|
12
12
|
この部分をpythonで表現するにはどうすればいいかご教授下さい。
|
13
13
|
|
14
|
+
タイムアウト時のエラー内容は以下となります。
|
15
|
+
```
|
16
|
+
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None
|
17
|
+
Message: unexpected alert open: {Alert text : タイムアウトしました}
|
18
|
+
(Session info: chrome=72.0.3626.109)
|
19
|
+
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5
|
20
|
+
ab),platform=Windows NT 6.3.9600 x86_64)
|
21
|
+
```
|
22
|
+
|
14
23
|
よろしくお願いいたします。
|