本文详细介绍了seleniumchromedriver在服务器上运行的详细方式,对大家来说非常详细。对大家的学习、培训或者工作都有一定的参考价值,一定要朋友们参考。
1。序言
我想用selenium从URL中抓取数据信息,但是有时候phantomjs的应用会失败。现在,chrome有界面运行模式吗?之后,幻像就可以消除了。
然而,在服务器上安装chrome时出现了一些错误。下面是整个安装过程的总结。
2。在Ubuntu上安装Chrome
#InstallGoogleChrome #https://askubuntu.com/questions/79280/how-to-install-chrome-browser-properly-via-command-line sudoapt-getinstalllibxss1libappindicator1libindicator7 wgethttps://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudodpkg-igoogle-chrome*.deb#Mightshow"errors",fixedbynextline sudoapt-getinstall-f这应该已经安装好了。使用以下命令行运行测试:
Google-chrome-headless-remote-debugging-port=9222https://chromium.org-disable-GPU
这里采用无头方式进行遥控调节。大多数ubuntu没有gpu,所以——-disable-GPU防止出错。
以后可以再打开一个到服务器的ssh连接,用cmd浏览服务器的本地端口9222:
curlhttp://localhost:9222
如果安装,您将看到调试信息。但是我会在这里报告一个错误。以下是错误的解决方案。
1)很可能是错误的解决方案
运行以上指令后,你很可能会报错,root下无法运行chrome。这时候在下面设置chrome。
1.寻找谷歌浏览器文档
该地图位于/opt/google/chrome/
2.用vi打开google-chrome文档
VI/opt/谷歌/chrome/谷歌浏览器
在文档中查找
exec-a"[18]""$HERE/chrome""$@"
3.只要在最后加上–user-data-dir–no-sandbox,就是一个shell指令。
exec-a"[20]""$HERE/chrome""$@"-用户数据目录无沙箱
4.再次打开google-chrome正常浏览一切!
3.安装chrome驱动程序
免费下载chromedriver
Chromedriver展示的是实际 *** 作chrome的api,是selenium *** 作chrome的公路桥。
Chromedriver最好安装最新版本。记住,我一开始没有安装最新版本,我会报错。最新版本的chromedriver没有任何问题。最新版本可以在以下详细地址找到
https://sites.Google.com/a/chromium.org/chromedriver/downloads。
当我写这篇文章的时候,最新的版本是2.37
wgethttps://chromedriver.storage.GoogleAPIs.com/2.37/chromedriver_linux64.zip
解压chromedriver_Linux64.zip
这里安装的是chrome的服务器端无界版本。
4.无界铬 *** 作方法
fromseleniumimportwebdriver chrome_options=webdriver.ChromeOptions() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') chrome_options.add_argument("user-agent='Mozilla/5.0(X11;Linuxx86_64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/62.0.3202.94Safari/537.36'") wd=webdriver.Chrome(chrome_options=chrome_options,executable_path='/home/chrome/chromedriver') wd.get("https://www.163.com") content=wd.page_source.encode('utf-8') printcontent wd.quit()这里,chrome_options中的第三项设置了主要参数。应用此设置可以防止网站安全检测到您正在使用无限制的方式进行反爬取。
另外,以下两项设置,未设置时,在pclinux系统软件或mac系统上打开chromewithinterface。调整时可以注意到下面两行应用chromewithinterface调试程序。
chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu')5.参考
https://Jiayi.space/post/zai-ubuntufu-Wu-qi-Shang-Shi-Yong-chrome-headless
https://blog.csdn.net/u013703963/article/details/71083802
摘要
到目前为止,这篇关于运行在服务器上的seleniumchromedriver的文章已经在这里详细介绍过了。关于在服务器上运行的seleniumchromedriver的大量信息,请搜索您以前的文章或再次访问下面的相关文章。期待你以后的申请!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)