pythonにてseleniumを使いWebスクレイピングをやり始めました。
python
1link_attrs = driver.find_elements_by_class_name('mypage-item-link') 2status_attrs = driver.find_elements_by_class_name('mypage-item-status') 3 4for (link, status) in zip(link_attrs, status_attrs): 5 # 詳細ページへ 6 print(status.text) 7 driver.get(link.get_attribute("href")) 8 first = driver.find_element_by_xpath('/html/body/div/main/div[2]/section[1]/div/ul/li[7]/ul/li/p[1]') 9 last= driver.find_element_by_xpath('/html/body/div/main/div[2]/section[1]/div/ul/li[7]/ul/li/p[2]') 10 11 time.sleep(2) 12 driver.back() 13 time.sleep(10) 14 15 driver.close()
コードの一部になりますが、これを実行した際
python
1Traceback (most recent call last): 2 File "C:/Users/xx/PycharmProjects/untitled/hoge.py", line 6, in <module> 3 print(status.text) 4 File "C:\Users\xx\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 76, in text 5 return self._execute(Command.GET_ELEMENT_TEXT)['value'] 6 File "C:\Users\xx\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute 7 return self._parent.execute(command, params) 8 File "C:\Users\xx\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute 9 self.error_handler.check_response(response) 10 File "C:\Users\xx\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response 11 raise exception_class(message, screen, stacktrace) 12selenium.common.exceptions.WebDriverException: Message: invalid session id 13 (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)
と、このようなエラーが出てしまい、二回目以降のstatus.text
が抽出出来ません
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。