【问题标题】:How to read text in a PDF如何阅读 PDF 中的文本
【发布时间】:2017-06-01 20:45:37
【问题描述】:

我正在尝试学习如何使用 Selenium 的 IE 驱动程序阅读 PDF 中的文本。我收到 selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with css selector == body

from selenium import webdriver
import time

TO_url = "Y:\Work\Work\PFCToolbox\exampleTO\HT072663_001.pdf"
vpc_url = "http://dspgot03.vcc.ford.com/apps/vpc/vpc.nsf/"
driver = webdriver.Ie()
driver.get(TO_url)
element = driver.find_element_by_css_selector("body")
time.sleep(10)

我也尝试使用其他 driver.find_element_by 函数,但找不到有效的函数

【问题讨论】:

  • 您有示例网址吗?
  • 您可能想要下载 pdf,然后使用 pdfrw 等库来阅读其内容。

标签: python selenium pdf


【解决方案1】:

不要找到body 元素,而是尝试发送密钥来获取文本:

driver.send_keys(Keys.CONTROL, 'a')
driver.send_keys(Keys.CONTROL, 'c')

然后从剪贴板粘贴。

【讨论】:

    猜你喜欢
    • 2013-04-18
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多