我正在使用Python从一个网站上抓取内容。首先,我在Python上使用了BeautifulSoup和Mechanize,但我看到网站上有一个通过JavaScript创建内容的按钮,所以我决定使用Selenium。
既然我可以通过像driver.find_element_by_xpath这样的方法使用Selenium查找元素并获取它们的内容,那么当我可以使用Selenium做任何事情时,还有什么理由使用BeautifulSoup呢?
在本例中,我需要使用Selenium来单击JavaScript按钮,所以使用Selenium进行解析更好,还是应该同时使用Selenium和Beautiful S
下面是使用Selenium和Firefox在Python中下载网页的代码。页面的一部分是用Javascript呈现的,所以我想等到一个短语呈现出来。
这是我正在使用的代码:
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
我在selenium中尝试了这么多xpath,但都无法点击元素,总是给我一个错误,元素找不到或元素无法交互如何解决它将不胜感激,下面是元素的xpath:
(//a[@href='javascript:void(0)' and @class='select2-choice select2-default'])[1]
我有一个凭证(使用Python),它提交给www.example.com/ form /info.php上的一个表单。
目前,我的脚本将:-打开Firefox -输入名称,年龄,地址-按提交
我想要做的是在LAMP上有一个web表单(带有名称、年龄、地址),当用户按submit时,它会将这些选项添加到selenium脚本中(放到www.example.coom/ form /info.php中),并直接在浏览器中提交。这个是可能的吗?
更新:我知道使用是可能的,因为我已经对它进行了测试,但它与javascript不太好,这就是我使用selenium的原因。
我有一个参数化的pytest测试套件。每个参数都是一个特定的网站,测试套件使用Selenium自动化运行。在考虑了参数之后,我总共有数百个测试,它们都是按顺序运行的。 每周一次,Selenium会因为各种原因而失败。连接丢失,无法实例化chrome实例等。如果它在测试运行过程中失败一次,它将使所有即将进行的测试崩溃。以下是一个失败日志示例: test_example[parameter] failed; it passed 0 out of the required 1 times.
<class 'selenium.common.exceptions.WebDrive
我有Arch,最近它的python包升级到了第三个分支。现在我无法运行selenium-python绑定。当我运行它(即使是旧的python版本)时,我得到:
from selenium import selenium
File "/usr/lib/python2.7/site-packages/selenium-2.0a5-py2.7.egg/selenium/__init__.py", line 23, in <module>
from selenium.selenium import selenium
File "/usr/li