小编Deb*_*anB的帖子

如何使Selenium不等到整页加载,脚本速度慢?

Selenium driver.get (url)等到整页加载.但是抓取页面试图加载一些死的JS脚本.所以我的Python脚本等待它并且几分钟不起作用.此问题可能出现在网站的每个页面上.

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.cortinadecor.com/productos/17/estores-enrollables-screen/estores-screen-corti-3000')
# It try load: https://www.cetelem.es/eCommerceCalculadora/resources/js/eCalculadoraCetelemCombo.js 
driver.find_element_by_name('ANCHO').send_keys("100")
Run Code Online (Sandbox Code Playgroud)

如何限制等待的时间,阻止文件的AJAX加载,还是以其他方式?

我也在测试我的脚本webdriver.Chrome(),但是会使用PhantomJS(),或者可能是Firefox().因此,如果某些方法使用浏览器设置的更改,那么它必须是通用的.

python selenium google-chrome selenium-chromedriver pageloadstrategy

14
推荐指数
2
解决办法
1万
查看次数

'Webdrivers'可执行文件可能具有错误的权限.请参阅https://sites.google.com/a/chromium.org/chromedriver/home

我环顾四周检查了两份文件并找不到答案.

我一直在尝试使用InstaPy为python进行instagram api.失败后出现多个错误,并假设InstaPy只是遇到了一些问题,所以我尝试使用selinium对其进行原始编码.在插入示例代码并将其改为我喜欢之后,我确保这个代码能够正常工作.我收到了一个新错误而不是旧错误,说权限可能不对.我尝试重新安装并以管理员身份运行,但没有任何作用.我该如何解决这个和/或这是什么意思

码:

import time
from selenium import webdriver

driver = webdriver.Chrome('C:\Webdrivers')  # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo) …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver selenium-webdriver

14
推荐指数
4
解决办法
3万
查看次数

WebDriverException:消息:使用safaridriver和Selenium 3.13.0进行显式等待时找不到命令'GET /session/7.../displayed'

我正在使用下面的显式等待来检查元素是否可点击.

WebDriverWait(driver, 30).until(
        expected_conditions.element_to_be_clickable((By.CSS_SELECTOR, "#search")))
Run Code Online (Sandbox Code Playgroud)

但我得到错误

 <class 'selenium.common.exceptions.WebDriverException'>
Message: The command 'GET /session/.../displayed' was not found.
Run Code Online (Sandbox Code Playgroud)

如果我使用time.sleep()它工作正常而不是explicir等待它工作正常.我已经初始化了safari驱动程序

from selenium.webdriver import Safari
driver = Safari()
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪

  File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/support/wait.py", line 71, in until
    value = method(self._driver)
  File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/support/expected_conditions.py", line 283, in __call__
    element = visibility_of_element_located(self.locator)(driver)
  File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/support/expected_conditions.py", line 127, in __call__
    return _element_if_visible(_find_element(driver, self.locator))
  File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/support/expected_conditions.py", line 147, in _element_if_visible
    return element if element.is_displayed() == visibility else False
  File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/webelement.py", line 490, in is_displayed
    return self._execute(Command.IS_ELEMENT_DISPLAYED)['value']
  File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/webelement.py", line 628, …
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-webdriver safaridriver selenium3

14
推荐指数
1
解决办法
861
查看次数

p:nth-​​child(2)和p:nth-​​of-type(2)之间有什么区别?

p:nth-child(2)和之间有什么区别p:nth-of-type(2)

根据W3Schools CSS选择器参考:

  • p:nth-child(2):选择<p>作为其父级的第二个子元素的每个元素.
  • p:nth-of-type(2):选择作为其父元素<p>的第二个<p>元素的每个元素.

所不同的似乎是其父母的孩子<p> 其父母的元素.

如果我们已经<p>在两种情况下都提到了元素类型,并且关键字parent建立了父子关系,那么有什么区别呢?

css css-selectors css3

13
推荐指数
5
解决办法
945
查看次数

无法使用Selenium自动化Chase站点登录

当我尝试使用Selenium(Python)登录Chase网站时,我遇到以下错误消息:

追逐登录失败图像

但是,使用"人"登录工作正常.似乎当Selenium找到一个元素时会引发问题.

我错过了什么吗?我试图在stackoverflow上找到答案,但无济于事.

更新:

预期的结果是脚本将成功允许我以编程方式登录.

这是下面的代码示例:

import time
import os

from selenium import webdriver

CHASE_USER_ID = os.getenv('CHASE_USER_ID', None)
CHASE_PASSWORD = os.getenv('CHASE_PASSWORD', None)

assert CHASE_USER_ID is not None, 'Chase user id not set'
assert CHASE_PASSWORD is not None, ' Chase password not set'


def main():
    chrome_options = webdriver.ChromeOptions()
    driver = webdriver.Chrome(r'./chromedriver', chrome_options=chrome_options)

    try:
        driver.get('https://secure07c.chase.com/web/auth/#/logon/logon/chaseOnline?')

        time.sleep(2)

        user_element = driver.find_element_by_id('userId-input-field')  # Finding an element here seems to make the login process fail 
        user_element.send_keys(CHASE_USER_ID)

        password_element = driver.find_element_by_id('password-input-field')
        password_element.send_keys(CHASE_PASSWORD)

        time.sleep(2)

        password_element.submit()

        time.sleep(10)
    finally:
        driver.quit()


if …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome webdriver selenium-chromedriver

13
推荐指数
1
解决办法
1836
查看次数

启动 Chrome 并尝试使用 ChromeDriver 使用 Selenium 访问网页时如何解决“获取默认适配器失败”错误

我已经更新了 Selenium,但即使加载了网页,错误也会不断发生。但是,在某些情况下,驱动程序启动但停滞不前。这是否会导致问题,如果是,我该如何解决?

[11556:9032:0502/152954.314:ERROR:device_event_log_impl.cc(162)] [15:29:54.314] Bluetooth: bluetooth_adapter_winrt.cc:1055 Getting Default Adapter failed.
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver selenium-webdriver

13
推荐指数
1
解决办法
4万
查看次数

使用jq如何用其他东西替换键的名称

这应该很容易......我想重命名几个键(理想情况下用jq),不管我做什么似乎都是错误的.示例json如下:

[
 {
  "fruit": "strawberry",
  "veg": "apple",
  "worker": "gardener"
 }
]
Run Code Online (Sandbox Code Playgroud)

我想将veg键重命名为fruit2(或者示例,无论什么是最简单的)以及作业的工作键.

我意识到这在sed中是可能的,但我正试图掌握jq :)

json key edit jq

12
推荐指数
2
解决办法
5068
查看次数

WebDriverException:消息:服务chromedriver意外退出.状态代码是:127

我想在我的服务器上使用selenium构建我的爬虫.

因此我在我的Ubuntu17.10服务器上安装/下载了所需的依赖项 - 例如chromedriver,chromium-browser等

但是,当我运行以下代码时:

driver = webdriver.Chrome()
Run Code Online (Sandbox Code Playgroud)

它返回以下错误:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-14-2cdab8938403> in <module>()
----> 1 driver = webdriver.Chrome()

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options)
     66             service_args=service_args,
     67             log_path=service_log_path)
---> 68         self.service.start()
     69 
     70         try:

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
     96         count = 0
     97         while True:
---> 98             self.assert_process_still_running()
     99             if self.is_connectable():
    100                 break

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
    109             raise WebDriverException(
    110                 'Service %s unexpectedly exited. Status code was: %s'
--> 111                 % …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver selenium-webdriver

12
推荐指数
5
解决办法
3万
查看次数

如何在 Selenium Webdriver Python 3 中使用 Chrome 配置文件

因此,每当我尝试使用 Chrome 设置(我在默认浏览器中使用的设置)时,添加

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\Users\... (my webdriver path)")
driver = webdriver.Chrome(executable_path="myPath", options=options)
Run Code Online (Sandbox Code Playgroud)

它向我展示了错误代码

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes n 16-17: truncated \UXXXXXXXX escape
Run Code Online (Sandbox Code Playgroud)

在我的 bash 中。我不知道这意味着什么,如果我能得到任何帮助,我会很高兴。提前致谢!

python selenium google-chrome selenium-chromedriver chrome-profile

12
推荐指数
4
解决办法
4万
查看次数

selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素无法用Selenium和Python点击

我目前正在从事一个自动填写表格的项目。填写表单时会出现下一个按钮,这就是为什么它给我一个错误。

我试过了:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//input[@type='button' and @class='button']")))
Next = driver.find_element_by_xpath("//input[@type='button' and @class='button']")
Next.click()
Run Code Online (Sandbox Code Playgroud)

HTML:

<span class="btn">
    <input type="button" value="Next" class="button" payoneer="Button" data-controltovalidate="PersonalDetails" data-onfieldsvalidation="ToggleNextButton" data-onclick="UpdateServerWithCurrentSection();" id="PersonalDetailsButton">
     </input>
     <div class="clearfix"></div>
</span>
Run Code Online (Sandbox Code Playgroud)

错误:

selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素在点 (203, 530) 处不可点击。其他元素将收到点击:...(会话信息:chrome=76.0.3809.132)

python selenium xpath css-selectors webdriverwait

12
推荐指数
3
解决办法
3万
查看次数