- Python Selenium: How to get the innerHTML from element
- Python Selenium: How to get the innerHTML from element
- Solution
- Getting inner HTML with python’s selenium not working
- How to get innerHTML of whole page in selenium driver?
- Get HTML source of WebElement in Selenium WebDriver using Python
- Get HTML Source of WebElement in Selenium WebDriver using Python.
- Syntax
- Syntax
- Example
Python Selenium: How to get the innerHTML from element
Solution 3: Sure we can get all HTML source code with this script below in Selenium Python: If you you want to save it to file: I suggest saving to a file because source code is very very long. Using page object in Java: Solution 4: A C# snippet for those of us who might want to copy / paste a bit of working code some day Thanks to those who answered before me.
Python Selenium: How to get the innerHTML from element
I want to get get the innerHTML from a element but when it run it get error say:
findtable.get_attribute('innerHTML') AttributeError: 'list' object has no attribute 'get_attribute'
#findtable findtable = driver.find_elements(By.XPATH, "/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td[1]/center/img") findtable.get_attribute('innerHTML')
find_elements* returns a list , where as to identify a single element you need find_element* .
Additionally, get_attribute() is a WebElement method.
Solution
You need to change driver.find_elements() as driver.find_element() , you’ll be good to go.
Your effective code block will be:
findtable = driver.find_element(By.XPATH, "/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td[1]/center/img") findtable.get_attribute('innerHTML')
instead of driver.find_elements() use driver.find_elements() without s at the end
findtable = driver.find_element(By.XPATH, "/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td[1]/center/img") findtable.get_attribute('innerHTML')
Python Selenium: How to get the innerHTML from element, Browse other questions tagged python selenium selenium-webdriver innerhtml getattribute or ask your own question. The Overflow Blog The internet’s Robin Hood uses robo-lawyers to fight parking tickets and spam
Getting inner HTML with python’s selenium not working
I am trying to scrape a JS enabled webpage, but I am not able to access the HTML code that is seen in my web browser. I am successfully logging into and navigating to the relevant url. However, getting the inner html is not working.
from selenium import webdriver browser = webdriver.Chrome("path-to-webdriver") page = browser.get(url) inner_html = browser.execute_script("return document.body.innerHTML") print(inner_html)
Below is the part of the HTML code that I want to become accessible; it is inside the first tags. The JS script generating the content is found below. The output of my python script contains no extra information compared to the HTML code presented below.
So, how I can get the inner HTML code of this page?
The part of the HTML I want is printed below, particularly the «Last update:» part.
Jottonian time: 2018-02-26 09:24 Last update: 166:24 hours ago Issues: Quite some