首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >硒:无头模式

硒:无头模式
EN

Stack Overflow用户
提问于 2022-08-31 07:24:51
回答 1查看 21关注 0票数 1

我刚学到了selenium模块,我看的视频是大约1年前的。这个例子是

代码语言:javascript
运行
复制
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = webdriver.ChromeOptions()
chrome_options.headless=True

path='/usr/bin/google-chrome'
chrome_options.binary_location = path

driver = webdriver.Chrome(executable_path=chrome_options.binary_location,options=chrome_options)

url="https://www.jd.com/?country=USA"
driver.get(url)
driver.save_screenshot("jingdong.png")

当重新使用时,会发生错误。

意外异常格式异常。回到标准的例外..。

在搜索多个文档之后,我发现参数发生了一些变化。为此,我想与大家分享我的发现。为像我这样的新手解释一下这篇文章。

EN

回答 1

Stack Overflow用户

发布于 2022-08-31 07:24:51

代码语言:javascript
运行
复制
from selenium import webdriver

# this is for finding elements, by_id/class/tag...
from selenium.webdriver.common.by import By

#this is for adding the chromedriver options such as headless, gpu-enable
from selenium.webdriver.chrome.options import Options


#Add options, the headless should be used in this way instead of "add_argument"
chrome_options = Options()
chrome_options.headless=True 
# setting it = true, enable headless mode

# this is for the driver path
executable= "/home/fish/Documents/WebScraping/driver/chromedriver_ubuntu"

# split the options and executable_path!!!
driver = webdriver.Chrome(executable_path=executable, options=chrome_options)


#Here is just my random trial for examining if the headless work
url="https://https://www.google.com.**/"
driver.get(url)
driver.save_screenshot("google.png")

因此,selenium无头模式适用于我。

我的系统: ubuntu22.04

软件:木星笔记本(ANaconda)

日期:2022831(以防以后selenium对其参数有其他更改)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73552250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档