WebDriverException:消息:服務(wù)/ content / chromedriver意外退出狀態(tài)代碼為:-6(使用ChromeDriverGoogle Colab和Selenium)
我已經(jīng)找到了有關(guān)為什么我出錯(cuò)的問(wèn)題的答案。請(qǐng)安裝chrome-chromedriver,并將其添加到您的路徑變量以及bin目錄中。
這是解決如何在Colab上使用Selenium抓取數(shù)據(jù)的完整解決方案。使用PhantomJS還有另一種方法,但是Selenium已棄用此API,希望他們?cè)谙乱淮蜸elenium更新中將其刪除。
# 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
這對(duì)于想要在Google Colab上而不是在您的本地計(jì)算機(jī)上抓取數(shù)據(jù)的任何人都有效。請(qǐng)按相同順序依次執(zhí)行以下步驟。
您可以在https://colab.research.google.com/drive/1GFJKhpOju_WLAgiVPCzCGTBVGMkyAjtk中找到筆記本。
解決方法我試圖使用Selenium運(yùn)行無(wú)頭Chrome瀏覽器以從網(wǎng)絡(luò)上抓取內(nèi)容。我使用wget安裝了無(wú)頭Chrome,然后將其解壓縮到當(dāng)前文件夾中。
!wget 'http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip'!unzip chromedriver_linux64.zip
現(xiàn)在,當(dāng)我加載驅(qū)動(dòng)程序時(shí)
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)
我收到一個(gè)錯(cuò)誤
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)過(guò)一些研究,我嘗試了另一種方法
!apt install chromium-chromedriverimport selenium as seoptions = se.webdriver.ChromeOptions()options.add_argument(’headless’)driver = se.webdriver.Chrome(chrome_options=options)
在Google Colab上,這再次給了我相同的錯(cuò)誤
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: -6
相關(guān)文章:
1. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問(wèn)題。2. javascript - Ajax加載Json時(shí),移動(dòng)端頁(yè)面向左上角縮小一截兒,加載完成后才正常顯示,這該如何解決?3. mysql - 記得以前在哪里看過(guò)一個(gè)估算時(shí)間的網(wǎng)站4. python運(yùn)行后沒(méi)有任何反饋要怎么排查5. javascript - h5 video層級(jí)太高導(dǎo)致浮在div上面,如何解決?6. mysql刪除一個(gè)空數(shù)據(jù)庫(kù)報(bào)錯(cuò)Table storage engine for ’proc’ doe7. 更新mysql中被別人鎖定的行, 能不能快速失敗直接報(bào)錯(cuò), 而不是一直等待8. python小白 想做一個(gè)能夠計(jì)算圓周率的代碼,不知道怎么寫9. javascript - 如何獲取未來(lái)元素的父元素在頁(yè)面中所有相同元素中是第幾個(gè)?10. javascript - 我的站點(diǎn)貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?
