前提・実現したいこと
ハローワークの求人情報検索サイトから、Seleniumを使って、自動的に求人情報を抽出するツールを作ろうとしています。
最初に雇用形態と求人のエリアを選択することはできましたが、検索ボタン(input)タグのボタンをクリックしようとすると、タイムアウトして下記のエラーメッセージが出てしまい、上手く行きません。
inputタグの座標を捉え、なおかつ画面に表示されているにも関わらず、クリックできないのです。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "./autohelloworks2.py", line 56, in <module> get_work_info() File "./autohelloworks2.py", line 47, in get_work_info botton_elem = html_wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//input[@id='ID_commonSearch']"))) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
該当のソースコード
Python
1#! /usr/bin/python3 2import bs4,requests,time,os,sys,random,re 3from selenium import webdriver 4from selenium.webdriver.common.by import By 5from selenium.webdriver.support.ui import WebDriverWait 6from selenium.webdriver.support import expected_conditions 7from selenium.webdriver.common.alert import Alert 8from selenium.webdriver.common.keys import Keys 9from selenium.webdriver import Firefox, FirefoxOptions 10 11#ヘッドレスモードで起動させる。 12options = FirefoxOptions() 13#options.add_argument('-headless') 14 15browser = webdriver.Firefox(options=options) 16browser.get("https://www.hellowork.go.jp/servicef/130020.do?action=initDisp&screenId=130020") 17TIMEOUT = 10 18 19def get_work_info(): 20 21 try: 22 html_wait = WebDriverWait(browser,3) 23 print("HTML取得中") 24 html_elem = html_wait.until(expected_conditions.visibility_of_element_located((By.TAG_NAME, "html"))) 25 print("HTML取得完了") 26 except: 27 print("HTMLの取得に失敗しました") 28 29 else: 30 31 part_time = browser.find_element_by_id("ID_LkyujinShurui2") 32 part_time.click() 33 area = browser.find_element_by_id("ID_todofuken24") 34 area.click() 35 36 print("下へ") 37 38 botton_elem = browser.find_element_by_xpath("//input[@id='ID_commonSearch']") 39 y_pos = botton_elem.location["y"] 40 print(y_pos) 41 print("ボタン検出完了") 42 43 browser.execute_script("window.scroll(0 , " + str(y_pos) + ");") 44 time.sleep(3) 45 46 #ボタンのクリック(ここでクリックができていない) 47 html_wait = WebDriverWait(browser,TIMEOUT) 48 botton_elem = html_wait.until(expected_conditions.visibility_of_element_located((By.XPATH,"//input[@id='ID_commonSearch']"))) 49 botton_elem.click() 50 51 52if __name__ == "__main__": 53 try: 54 55 get_work_info() 56 57 except KeyboardInterrupt: 58 print("\nprogram was ended.\n") 59 sys.exit()
試したこと
検索ボタンのinputタグの取得方法(IDやクラス名、name属性など)を工夫してみましたが、いずれもうまく行きませんでした。
補足情報(FW/ツールのバージョンなど)
Python3.6.7
Ubuntu18.04

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。