小编Lou*_*ise的帖子

如何使用selenium和python在phantomjs中设置cookie?

在此输入图像描述

它引发了一条错误消息"只能为当前域设置Cookie",但我所做的只是将旧的cookie放入.有时我添加'正确'域,它会引发错误消息"无法设置Cookie".我在Firefox中测试过,Firefox也无法工作.

from selenium import webdriver
driver = webdriver.PhantomJS(executable_path=phantompath)
driver.get('http://stackoverflow.com/')
driver.get_screenshot_as_file('1.png')
cookies = driver.get_cookies()
driver.delete_all_cookies()
driver.get_cookies()
for cookie in cookies:
    driver.add_cookie(cookie)
Run Code Online (Sandbox Code Playgroud)

python cookies selenium phantomjs

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

selenium无法截取网页元素

在此输入图像描述

我可以使用Firefox.get_screenshot_as_file('2.png')截取整个页面,但是当我使用passage.screenshot('1.png')截取网页元素时,它总是引发此异常:

selenium.common.exceptions.WebDriverException: Message: Unrecognized command: GET /session/284283fa-53fc-4b33-b329-e6e888dbdcb0/screenshot/{35834cf1-c9c7-4129-99b1-24f30c6b56e6}
Run Code Online (Sandbox Code Playgroud)

python firefox selenium

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

标签 统计

python ×2

selenium ×2

cookies ×1

firefox ×1

phantomjs ×1