我正在尝试抓取页面,但有时无法单击链接/按钮。
加载网页时,只要该框出现在网站上,“ loadingWhiteBox”将首先出现,然后在几秒钟后消失(但它将保留在HTML代码中),我无法单击链接,并且得到以下错误信息:
selenium.common.exceptions.ElementClickInterceptedException: Message:
Element <span class="taLnk ulBlueLinks"> is not clickable at point
(318.3000030517578,661.7999877929688) because another element <div
class="loadingWhiteBox"> obscures it
Run Code Online (Sandbox Code Playgroud)
有什么办法可以解决此问题?我已经尝试使用以下命令:
driver.is_element_present_by_css('div[class*="loadingWhiteBox"]')
Run Code Online (Sandbox Code Playgroud)
但是即使该元素不处于活动状态,它也存在。
我做了以下但发现了错误:
selenium.common.exceptions.WebDriverException:消息:'chromedriver'可执行文件需要在PATH中.请参阅 https://sites.google.com/a/chromium.org/chromedriver/home
from splinter import Browser
browser = Browser('chrome')
Run Code Online (Sandbox Code Playgroud)
如何使用Mac解决问题?
提前谢谢,一定会upvote /接受答复!
我正在尝试使用Splinter的Firefox驱动程序来测试一些响应式设计.
当然,这需要我调整浏览器窗口的大小.我在文档中找不到任何关于浏览器大小调整的内容.
我怎样才能做到这一点?
from splinter import Browser
with Browser() as browser:
# How do I set the browser size?
Run Code Online (Sandbox Code Playgroud) 在较早版本的Splinter/Selenium中,据说这是不可能的.几年后这个答案声称它可以使用JavaScript,但是这段代码对我不起作用(我可能只是将它转换为Python).这个答案关闭浏览器,然后重新打开它,我需要窗口/浏览器保持打开状态.
使用像FoxyProxy这样的插件,它很容易即时更改代理,但我不认为Selenium可以与插件交互,因为它们是页面元素?
由于Splinter被设计为Selenium的一个不那么详细的包装器,如果有一个简单的方法可以实现这一点,那将是非常棒的.话虽如此,任何黑客只是拥有这个功能将不胜感激.
我正在尝试抓取网站" http://everydayhealth.com ".但是,我发现该页面将动态呈现.因此,当我点击"更多"按钮时,会显示一些新消息.但是,使用splinter单击按钮不会让"browser.html"自动更改为当前的html内容.有没有办法让它获得最新的html源,使用splinter或selenium?我在splinter中的代码如下:
import requests
from bs4 import BeautifulSoup
from splinter import Browser
browser = Browser()
browser.visit('http://everydayhealth.com')
browser.click_link_by_text("More")
print(browser.html)
Run Code Online (Sandbox Code Playgroud)
根据@Louis的回答,我重写了以下程序:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Firefox()
driver.get("http://www.everydayhealth.com")
more_xpath = '//a[@class="btn-more"]'
more_btn = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(more_xpath))
more_btn.click()
more_news_xpath = '(//a[@href="http://www.everydayhealth.com/recipe-rehab/5-herbs-and-spices-to-intensify-flavor.aspx"])[2]'
WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_xpath(more_news_xpath))
print(driver.execute_script("return document.documentElement.outerHTML;"))
driver.quit()
Run Code Online (Sandbox Code Playgroud)
但是,在输出文本中,我仍然无法在更新的页面中找到该文本.例如,当我搜索"Is Milk Your Friend or Foe?"时,它仍然没有返回任何内容.有什么问题?
所以我很难让硒与无头驱动器,特别是PhantomJS一起工作.我试图让它在Ubuntu网络服务器(Ubuntu 14.04.2 LTS)上运行.
从python解释器(Python 2.7.6)运行以下命令给出:
from selenium import webdriver
driver = webdriver.PhantomJS()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/service.py", line 76, in start
raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
driver = webdriver.PhantomJS(executable_path="/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, …
Run Code Online (Sandbox Code Playgroud) 目前,使用Python和Splinter,我需要准确定义option1
在页面上找到选项时单击的文本:
from splinter import Browser
browser = Browser('chrome')
browser.find_option_by_text(option1).first.click()
Run Code Online (Sandbox Code Playgroud)
但如果option1
不在那里,我怎么能退回并选择任何可用的下一个选项而不是必须定义它?
是否可以在页面上找到一个选项并选择遇到的任何第一个可用选项,而无需定义选项?
提前谢谢你,一定会upvote /接受答复
在我的python项目中,我使用Splinter(https://splinter.readthedocs.io/en/latest/)打开浏览器并尝试访问网站:
from splinter import Browser
browser = Browser('chrome')
browser.visit('http://www.google.com')
Run Code Online (Sandbox Code Playgroud)
并且浏览器打开了,无法访问http://www.google.com
,它收到以下错误:
Traceback (most recent call last):
File "practice.py", line 90, in <module>
browser = Browser('chrome')
File "/Library/Python/2.7/site-packages/splinter/browser.py", line 63, in Browser
return driver(*args, **kwargs)
File "/Library/Python/2.7/site-packages/splinter/driver/webdriver/chrome.py", line 31, in __init__
self.driver = Chrome(chrome_options=options, **kwargs)
File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 185, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 247, in execute
response = …
Run Code Online (Sandbox Code Playgroud) 我试图用分裂填写登录表单上的字段.当我检查渲染页面时,我看到用户名输入框同时包含一个标记和名称"u".如何从分裂中填写此字段?我尝试了以下方法:
from splinter import Browser
url = "http://www.weiyun.com/disk/login.html"
browser = Browser('firefox')
browser.visit(url)
browser.fill("u", "foo@bar.com")
print "done"
Run Code Online (Sandbox Code Playgroud)
但根据返回的错误,没有这样的字段:
ElementDoesNotExist: no elements could be found with name "u"
Run Code Online (Sandbox Code Playgroud)
如何使用splinter填充这样的页面上的输入字段?
一旦我将以下项目添加到购物车:http://www.supremenewyork.com/shop/accessories/wau85w4km/cxv3ybp1w并转到结帐页面:https://www.supremenewyork.com/checkout,有一个条款和条件复选框,我试图检查,Browser’s splinter
但我不能这样做:
例如,尝试了以下但是都遇到了错误:
from splinter import Browser
browser = Browser("chrome")
browser.find_by_id('order_terms').click()
#Error: selenium.common.exceptions.WebDriverException: Message: unknown error
browser.check('order[terms]').click()
#Error: selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
browser.find_by_name('order[terms]').click()
#Error: selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
Run Code Online (Sandbox Code Playgroud)
我能做错什么?我怎样才能选中复选框Browser splinter
?
提前谢谢你,一定会upvote /接受答复
splinter ×10
python ×9
selenium ×6
browser ×3
python-2.7 ×3
html ×2
exception ×1
forms ×1
javascript ×1
linux ×1
macos ×1
phantomjs ×1
python-3.x ×1
testing ×1
web-crawler ×1
web-scraping ×1