Reputation: 162
I want to get text of an email behind canvas, but not finding a way to do it.
I am trying the following code
from selenium import webdriver
driver=webdriver.Chrome()
driver.get('https://thatsthem.com/phone/806-241-6888')
table=driver.find_element_by_css_selector('.row.clearfix.mt15').get_attribute('innerHTML')
When I print table I don't see variable behind canvas (like var p1 = "makaya0";). They can be seen in source code when I open "View Page source" on browser. How we can access that variables and get text from them?
Below is page Source
<ul class="list-unstyled list-inline record-list">
<li>
<span class="label label-info"> <i class="fa fa-check"></i> Mobile</span>
</li>
<li>
<i class="fa fa-phone" data-toggle="tooltip" title="Phone Number"></i>
<h3>
<span itemprop="telephone">806-241-6889</span>
</h3>
</li>
<li>
<span class="label label-success"><i class="fa fa-check"></i> Valid Email Address</span>
</li>
<li>
<i class="fa fa-envelope" data-toggle="tooltip" title="Email Address"></i>
<canvas id="c59baf787024e2" width="160" height="20" class="email"></canvas>
<script id="t2i">
var p1 = "makaya0";
var p2 = "923@yah";
var p3 = "oo.com";
var c59baf787024e2 = document.getElementById("c59baf787024e2");
var c59baf787024e2_context = c59baf787024e2.getContext("2d");
c59baf787024e2_context.fillStyle = "#353535";
c59baf787024e2_context.font = "98% sans-serif";
c59baf787024e2_context.textBaseline = "bottom";
c59baf787024e2_context.fillText(p1 + p2 + p3, 0, 20);
document.getElementById("t2i").parentElement.removeChild(document.getElementById("t2i"));
</script>
</li>
<li itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<i class="fa fa-home" data-toggle="tooltip" title="Address"></i>
<a class="no-linky" href="https://thatsthem.com/address/8114-Sherman-Ave-Lubbock-TX-79423">
<span itemprop="streetAddress">8114 Sherman Ave</span>
<br/> <i class="fa-placeholder"></i>
<span itemprop="addressLocality">Lubbock</span>
<span itemprop="addressRegion">TX</span>
<span itemprop="postalCode">79423</span>
</a>
</li>
</ul>
Upvotes: 0
Views: 2475
Reputation: 20768
the values you are talking about are javascript variables. they're not 'text' per say.
to run a script in javascript through selenium, you can do:
output = self.driver.execute_script("return p1;")
and it will put the value of variable p1
in javascript into the output
variable in python.
This assumes the variable p1 is in the global context, which it seems to be in your case.
Upvotes: 1