python-3.x - Selenium chrome --headless 如何工作?
问题描述
伙计们!与 selenium 一起使用的 chromedriver 中的基本模式和 --headless 模式之间的真正区别是什么?我问是因为我试图在 adidas.com 上跟踪一些价格,当我设置我的驱动程序时:
chrome_options = webdriver.ChromeOptions()
browser = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
browser.get(url)
浏览器在我的电脑上打开,一切正常。
但是当我试图执行下面的代码时:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
browser.get(url)
回应是:
'<html lang="en"><head>\n <meta charset="utf-8">\n <meta name="viewport"
content="width=device-width, initial-scale = 1.0, maximum-scale=1.0, user-
scalable=no">\n <title>adidas</title>\n\n <link
href="/WAFfailoverassets/style.css" rel="stylesheet">\n</head>\n<body>\n\n<main
class="content-wrapper">\n <header class="top">\n <div
class="logo">adidas</div>\n <span
id="ctl00_mainContentPlaceHolder_lblInvalidRequest">\n<br> Reference Error:
18.6c85655f.1629459608.2c05a32c </span>\n <h1 class="title">Unfortunately we
are unable to give you access to our site at this time. </h1>\n <p>A security
issue was automatically identified, when you tried to access the website.</p>\n
</header>\n\n <div class="columns">\n\n <section class="column column-1">\n
<h3>What could have caused this?</h3>\n <p>During high-traffic product
releases we have extra security in place to prevent bots entering our site. We do
this to protect customers and to give everyone a fair chance of getting the sneakers.
Something in your setup must have triggered our security system, so we cannot allow
you onto the site.</p>\n </section>\n\n <section class="column column-
2">\n <h3>How can I resolve this?</h3>\n <p>Please try
refreshing or accessing our website from a different browser or another device. You
could also check if there are any scripts, like ad blockers, running in your browser
and disable them. </p>\n <p>If this does not help, the issue might be
caused by malware. If you\'re on a personal connection you can run an anti-virus scan
on your device to make sure it\'s not affected by malware. If you\'re on a shared
network, you could ask the system administrator to run a scan looking for
misconfigured or infected devices across the network.</p>\n </section>\n\n
</div>\n\n <small class="error">HTTP 403 -
Forbidden</small>\n\n</main>\n\n\n\n</body></html>'
所以问题是网站如何检测它的代码是否真的呈现,如果我想在服务器上运行我的代码,我该如何处理?
解决方案
推荐阅读
- unity3d - 使用现有图像创建交互式地图的最佳方式
- bash - 为什么 echo -e "test" 会打印 "-e test"?
- java - Pangram在java中使用hashset
- jasper-reports - 如何从报告中访问报告名称属性?
- powershell - PowerShell 可执行 - 加倍努力还是放弃?
- javascript - 选择下拉菜单并为其设置样式
- node.js - 如何使用 node.js 在 heroku 上验证 google-vision api 凭据?
- node.js - 无法使用 Express+Pug (Jade) Web 应用程序使 Webpack “实时重新加载”功能
- python-3.x - 在 Python 中获取 Hybercubes 的所有完美匹配
- awk - AWK:无法打开“04477C9A875B80.csv”进行输出(打开的文件太多)