1
3

More than 3 years have passed since last update.

Python seleniumでelementからhtmlを取得する

Last updated at Posted at 2020-11-13

課題

seleniumを使用していて、find_element_by_class_nameなどのfind_element_by_〇〇で取得した要素について、ソースのHTMLを取得したい。

.page_sourceでソースを取得しようとするも、

AttributeError: 'WebElement' object has no attribute 'page_source'

というようなエラーが発生する。

解決法

以下の方法でHTMLを取得できる。

element.get_attribute('innerHTML')

参考: https://stackoverflow.com/questions/7263824/get-html-source-of-webelement-in-selenium-webdriver-using-python

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3