亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

WebDriverException:消息:服務(wù)/ content / chromedriver意外退出狀態(tài)代碼為:-6(使用ChromeDriverGoogle Colab和Selenium)

瀏覽:117日期:2024-05-16 15:57:17
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解決WebDriverException:消息:服務(wù)/ content / chromedriver意外退出狀態(tài)代碼為:-6(使用ChromeDriverGoogle Colab和Selenium)?

我已經(jīng)找到了有關(guān)為什么我出錯的問題的答案。請安裝chrome-chromedriver,并將其添加到您的路徑變量以及bin目錄中。

這是解決如何在Colab上使用Selenium抓取數(shù)據(jù)的完整解決方案。使用PhantomJS還有另一種方法,但是Selenium已棄用此API,希望他們在下一次Selenium更新中將其刪除。

# install chromium, its driver, and selenium!apt-get update!apt install chromium-chromedriver!cp /usr/lib/chromium-browser/chromedriver /usr/bin!pip install selenium# set options to be headless, ..from selenium import webdriveroptions = webdriver.ChromeOptions()options.add_argument(’--headless’)options.add_argument(’--no-sandBox’)options.add_argument(’--disable-dev-shm-usage’)# open it, go to a website, and get resultswd = webdriver.Chrome(’chromedriver’,options=options)wd.get('https://www.website.com')print(wd.page_source) # results

這對于想要在Google Colab上而不是在您的本地計算機(jī)上抓取數(shù)據(jù)的任何人都有效。請按相同順序依次執(zhí)行以下步驟。

您可以在https://colab.research.google.com/drive/1GFJKhpOju_WLAgiVPCzCGTBVGMkyAjtk中找到筆記本。

解決方法

我試圖使用Selenium運(yùn)行無頭Chrome瀏覽器以從網(wǎng)絡(luò)上抓取內(nèi)容。我使用wget安裝了無頭Chrome,然后將其解壓縮到當(dāng)前文件夾中。

!wget 'http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip'!unzip chromedriver_linux64.zip

現(xiàn)在,當(dāng)我加載驅(qū)動程序時

from selenium.webdriver.chrome.options import Optionsimport os# instantiate a chrome options object so you can set the size and headless preferencechrome_options = Options()chrome_options.add_argument('--headless')chrome_options.add_argument('--window-size=1920x1080')chrome_driver = os.getcwd() +'/chromedriver'driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chrome_driver)

我收到一個錯誤

WebDriverExceptionTraceback (most recent call last)<ipython-input-67-0aeae0cfd891> in <module>()----> 1 driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chrome_driver) 2 driver.get('https://www.google.com') 3 lucky_button = driver.find_element_by_css_selector('[name=btnI]') 4 lucky_button.click() 5 /usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py in __init__(self,executable_path,port,chrome_options,service_args,desired_capabilities,service_log_path) 60 service_args=service_args,61 log_path=service_log_path)---> 62 self.service.start() 63 64 try: /usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self) 84 count = 0 85 while True: ---> 86 self.assert_process_still_running() 87 if self.is_connectable(): 88 break /usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self) 97 raise WebDriverException( 98 ’Service %s unexpectedly exited. Status code was: %s’ ---> 99 % (self.path,return_code)100 )101WebDriverException: Message: Service /content/chromedriver unexpectedly exited. Status code was: -6更新資料

因此,經(jīng)過一些研究,我嘗試了另一種方法

!apt install chromium-chromedriverimport selenium as seoptions = se.webdriver.ChromeOptions()options.add_argument(’headless’)driver = se.webdriver.Chrome(chrome_options=options)

在Google Colab上,這再次給了我相同的錯誤

WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: -6

標(biāo)簽: web
相關(guān)文章:
主站蜘蛛池模板: 国产一区系列在线观看 | 二区在线视频 | 精品国产自在久久 | 91视频黄| 中文婷婷| 这里只有精品国产 | 亚洲精品一区二区久久 | 哪有黄色网址 | 亚洲一级网站 | 精品成人在线观看 | 欧美黄色性生活 | 91麻豆精品国产自产在线 | 国产大片喷水在线在线视频 | 伊人久久精品午夜 | 亚洲精品一区二区三区四区手机版 | 久久免费在线视频 | 一级国产仑乱 | 久久视频6免费观看视频精品 | 九九久久久2 | 国产欧美日韩在线人成aaaa | 亚洲视频在线观看不卡 | 91久久精一区二区三区大全 | 欧美精品国产综合久久 | 日本不卡免费新一二三区 | 在线精品国产成人综合第一页 | 韩国网站爱久久 | 香蕉视频黄色片 | 黄色电影毛片 | 中国国产aa一级毛片 | 国产一级aa大片毛片 | 免费国内精品久久久久影院 | 久久免费香蕉视频 | 亚洲欧美在线制服丝袜国产 | 91福利国产在线观看一区二区 | 视频一区二区在线观看 | 99国产精品 | 韩日一级视频 | 欧美 日产 国产精品 | 91天堂亚洲精品一区 | 国产乱码精品一区二区三 | 国产不卡一卡2卡三卡4卡5卡在线 |