python selenium如何复制站点的文本?
如何在使用python selenium如何复制站点的文本?,python,selenium,Python,Selenium,如何在使用python和selenium加载页面后复制文本。 网站的Html代码为: <html> <head> <link rel="alternate stylesheet" type="text/css" href="resource://gre-resources/plaintext.css" title="Wrap Long Lines"> </head> <body> <pre>32 251 305 266 0.
python
和selenium
加载页面后复制文本。
网站的Html代码为:
<html>
<head>
<link rel="alternate stylesheet" type="text/css" href="resource://gre-resources/plaintext.css" title="Wrap Long Lines">
</head>
<body>
<pre>32 251 305 266 0.992355
29 216 480 231 0.985983
152 76 825 92 0.983704
116 157 871 173 0.982307
26 181 535 197 0.971898
26 76 137 138 0.964413
25 17 682 40 0.961533
150 99 815 115 0.910050
101 118 242 142 0.783791
102 151 144 158 0.676560
</pre>
</body>
</html>
我想在中获取文本…
我该怎么办 您离输出很近,只需获取包含文本的标签并打印相同的内容。
示例:
基于您的代码
这将把
pre
标记的内容打印为文本错误:selenium.common.exceptions.NoSuchElementException:Message:找不到元素:/html/body/pre
@J.Drahimce,您使用的是Firefox 46及以上版本吗?Selenium webdriver在Firefox版本低于版本46时效果最佳。使用mytext=driver。通过xpath('/html/body')查找元素打印mytext.text
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
i=0
driver = webdriver.Firefox()
driver.get('http://www.textdet.com/')
e = driver.find_element_by_id("imagefile")
e.send_keys("/home/brm17/Desktop/ProjetFinDetude/image.png")
button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//a[contains(., "Download bounding boxes")]')))
button.click()
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
i=0
driver = webdriver.Firefox()
driver.get('http://www.textdet.com/')
e = driver.find_element_by_id("imagefile")
e.send_keys("/home/brm17/Desktop/ProjetFinDetude/image.png")
button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//a[contains(., "Download bounding boxes")]')))
button.click()
mytext = driver.find_element_by_xpath('/html/body/pre')
print mytext.text