Selenium:有没有一种方法可以从调试器(如Eclipse )中判断元素是否过时?
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
我用re模块用python编写了一个脚本,以便从网页中获得不同问题的标题。我在这里的意图是不使用BeautifulSoup,并且仍然能够解析标题。我用模式的方式可以做到这一点。但是,输出看起来不太好。我怎么能只得到问题的标题而没有别的。
下面是我的尝试(使用re.search()):
import requests
import re
link = "https://stackoverflow.com/questions/tagged/web-scraping"
res = requests.get(link).text
for item in res.splitlines
我尝试使用Python和Selenium从“”中自动检索数据。由于我无法找到我想要的元素,尽管我确信它是正确的,所以我用以下代码打印出了html内容:
from selenium import webdriver
from bs4 import BeautifulSoup as soup
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by
一个关于股票的网站有一个漂亮的图表,上面有几个显示图表的选项(参见https://www.boerse.de/chart-tool/HeidelbergCement-Aktie/DE0006047004)。我总是需要不同股票的图表,但图表的设置总是相同的,所以我想自动选择图表的设置。例如,我总是希望在图表类型<select id = "types"的选择框中选择"Barchart“(<option value = "Balken"> Bar-Chart </option>)选项。但我无法控制图表中的选项。可能是因为它是一个
标题说明了一切,我在python中找不到一个带有selenium的元素。
这是我的密码:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
s = Service("C:\Program Files (x8
如果我从Python启动Selenium并关闭浏览器窗口,我的脚本将在下次尝试让WebDriver执行某些操作时挂起。请注意,我是在关闭浏览器窗口的同时打开浏览器的--我在Mac上,浏览器(在我的例子中,Chrome)可以保持打开,即使没有任何窗口。下面是一个例子:
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.stackoverflow.com/")
time.sleep(5) # Let's say we close Chr
我在python中用selenium编写了一个脚本,以便从网页中获取标题地址。我在脚本中使用的url将在几秒钟内自动重定向。这就是我的脚本遇到错误的地方。我把那错误的一部分贴在纸上给你一个主意。
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
我试过的脚本:
from contextlib import
我试图通过使用selenium的python脚本自动从网站下载数据,但我得到了以下错误:
"WebDriverException: Message: TypeError: rect is undefined".
代码试用:
from selenium import webdriver
from selenium.webdriver.common import action_chains
driver = webdriver.Firefox()
url="https://www.hlnug.de/?id=9231&view=messwerte&detai
对于data_links中的链接:driver.get(链接)
review_dict = {}
# get the size of company
size = driver.find_element_by_xpath('//[@id="EmpBasicInfo"]//span')
#位置=?也需要得到这一部分。
我担心的是:
我正在尝试抓取一个网站。我正在使用selenium/python从跨度中剔除“501to1000名员工”和"Biotech &制药“,但我无法使用xpath.I从网站中提取文本元素。我尝试过getText,获取所有
我试着在网站上使用send_keys,这给了我一个元素不可交互的错误。
下面是我的代码:
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from s
我正在使用Python从一个网站上抓取内容。首先,我在Python上使用了BeautifulSoup和Mechanize,但我看到网站上有一个通过JavaScript创建内容的按钮,所以我决定使用Selenium。
既然我可以通过像driver.find_element_by_xpath这样的方法使用Selenium查找元素并获取它们的内容,那么当我可以使用Selenium做任何事情时,还有什么理由使用BeautifulSoup呢?
在本例中,我需要使用Selenium来单击JavaScript按钮,所以使用Selenium进行解析更好,还是应该同时使用Selenium和Beautiful S
我正在使用selenium和Python来抓取一个网站。我无法使用Beautiful Soup来抓取特定的表格。以下是代码 from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_condi
我对硒的研究还不太熟悉。当我在Selenium控制的web浏览器中做某些事情时,我试图触发对Python的调用。
例如,我在Python3.6.3中使用run按钮在Spyder中运行这个脚本。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from selenium import webdriver
b = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
from selenium.webdriver.support.events import E
我用python和selenium结合编写了一个脚本,从它的登陆页面中抓取不同帖子的链接,并通过跟踪指向其内部页面的url最终获得每个帖子的标题。虽然我在这里分析的内容是静态的,但我使用selenium来查看它在多处理中的工作方式。
然而,我的意图是使用多处理进行抓取。到目前为止,我知道selenium不支持多处理,但我似乎错了。
我的问题:当使用多进程运行时,如何减少使用selenium的执行时间?
This is my try (it's a working one)
import requests
from urllib.parse import urljoin
from mul
这是我第一次尝试使用Iceweasel浏览器在覆盆子pi上运行Selenium。今天晚上我做了一个简单的测试
# selenium test for /mod2
# verify: posts, and page name
class TestMod2Selenium(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_validate_page_elements(self):
driver = self.driver
我想使用python (subprocess.popen)启动selenium服务器命令,然后在该服务器上执行一些其他命令:
subprocess.popen(selenium Server command)
subprocess.popen(next command which should be launched while command selenium server is launched)
问题是,除非终止第二个命令,否则第一个命令不会终止,而且由于python等待第一个命令终止我的代码块,所以第二个命令永远不会启动
我应该使用多线程来实现这一点,还是有其他解决方案?既然我以前从
我正在用selenium测试django应用程序,我的一个页面使用。其中一个选项卡包含一个简单的表,列出了一些用户,并通过ajax加载。当使用应用程序时,选项卡工作得很好,但是当使用selenium自动测试时,选项卡似乎没有加载它的内容!我正在用python编写测试。一开始,我使用selenium的click方法,但正如我从以前的测试中痛苦地了解到的,在锚标记方面,这是相当错误的,所以我求助于我以前使用的解决方案: wait_for_condition方法,并显式地调用选项卡单击事件(甚至是load事件!)尽管如此,标签仍然不起作用!
I'm in despair here, the