简体   繁体   English

如何使用硒Python在画布后面获取文本

[英]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.

相关问题 如何使用 Python 驱动程序在 Selenium 和 web 驱动程序中获取部分文本 - How to get a part of text in Selenium and web driver using Python 如何使用 Selenium 和 Python 从由空格分隔的文本节点获取文本 - How to get text from textnodes seperated by whitespace using Selenium and Python 如何使用 selenium 和 python 从网站获取工具提示文本,其中文本来自 javascript - How can I get the tooltip text from a website using selenium and python where the text comes from a javascript 如何使用 Selenium Python (MacOS) 用自定义文本替换按钮文本? - How to replace a button text with customized text using Selenium Python (MacOS)? 如何通过Selenium和Python从html标签跨度获取文本 - How to get text from html tag span through Selenium and Python 如何使用 Selenium 和 Javascript 执行器查询 Canvas? - How to query the Canvas using Selenium and Javascript executor? 如何在画布和DynamicJS中使用硒进行拖放 - How to drag and drop using selenium in canvas and kineticjs 如何使用Selenium和Python将文本插入div节点 - How to insert a text into a div node using Selenium and Python 如何使用 selenium python 通过 send_keys 发送长文本 - how to send long text with send_keys using selenium python 如何使用 Python Selenium 从 angular 表单中提取输入文本? - How to extract the input text from angular form using Python Selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM