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