[英]How to get text behind canvas using selenium python
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";). 当我打印表格时,在画布后面看不到变量(例如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>
the values you are talking about are javascript variables. 您正在谈论的值是javascript变量。 they're not 'text' per say. 他们说的不是“文字”。
to run a script in javascript through selenium, you can do: 要通过selenium在javascript中运行脚本,您可以执行以下操作:
output = self.driver.execute_script("return p1;")
and it will put the value of variable p1
in javascript into the output
variable in python. 并将javascript中变量p1
的值放入python中的output
变量。
This assumes the variable p1 is in the global context, which it seems to be in your case. 假定变量p1在全局上下文中,这似乎在您的情况下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.