我正在尝试从我的cpanel运行一个python脚本。它使用selenium,尝试使用漂亮的soap提取html元素。下面是我的python代码
import os
from bs4 import BeautifulSoup
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(service=Service('/home/mesuivln/virtualenv/seopython/3.7/bin/chromedriver'))
driver.get ("https://www.tutorialspoint.com/about/about_careers.htm")
#content whole page in html format
s = BeautifulSoup(driver.page_source, 'html.parser')
#access to specific ul element with BeautifulSoup methods
l = s.find('ul', {'class':'toc chapters'})
#get all li elements under ul
rs = l.findAll('li')
for r in rs:
#get text of li elements
print(r.text)
在以下文件/virtualenv/seopython/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running return_code = self.process.poll()
中给出错误AttributeError: 'Service' object has no attribute 'process'
下面是上述文件第117行附近的代码
def assert_process_still_running(self) -> None:
"""Check if the underlying process is still running."""
return_code = self.process.poll()
if return_code:
raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
如何解决这个问题?我尝试在cpanel
上运行
1条答案
按热度按时间2w2cym1i1#
此代码中的问题在于,它试图使用
webdriver.Chrome class
,并将Service
对象作为服务参数传递。但这不是使用webdriver.Chrome
类的正确方法,因为它需要ChromeDriver
可执行文件的路径作为参数,而不是Service object.
而不是这个:
您应该使用以下命令: