I am trying to take information inside the tag.
<script type="text/javascript"> INFO </script>
More specifically:
<!DOCTYPE html>
<html lang="en" class="js logged-in client-root">
<head>...</head>
<body class style ="position: fixed; top: -265px; width: 100%;">
<span id="react-root" aria-hidden="true">...</span>
<script type="text/javascript> This is the tag i want. </script>
<script type="text/javascript>
window.__initialDataLoaded(window._sharedData); </script>
...
I am trying this but no luck:
browser = webdriver.Chrome()
info = browser.find_element_by_xpath("//script[@type='text/javascript']")
print(info.text) //prints nothing
In this article, we will write a Python Script for getting the text from the tag name using selenium module. We will be getting the tag text from this URL. Step #2: Create a Chrome object or specify web driver path if it is not present in the default path and assign URL. Step #3: Specify the tag name, which you want to extract the text.
To get it, first you need to have selenium and the web driver install. You can let Python fire the web browser, open the web page URL and grab the HTML source. To start, install the selenium module for Python. It’s recommended that you do that in a virtual environment using virtualenv.
It is a markup language. To get it, first you need to have selenium and the web driver install. You can let Python fire the web browser, open the web page URL and grab the HTML source. To start, install the selenium module for Python.
In this tutorial, we will learn How To Handle Web Tables in Selenium Python. A web table in an HTML document is defined under <table> tag. The rows of a table are represented with the <tr> tag and the columns in a table are represented with the <td> tag. Mostly each table has headers represented with the <th> tag.
Seems like this is the expected behavior. See here:
This is working correctly.
WebElement#getText
returns the visible text that a user can see. The user cannot see text in a<script>
tag, so it is not returned bygetText
. You can still access contents of the tag through JavaScript
So you will have to do something like this:
info.get_attribute('innerHTML')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With