Python 3.x 获取错误“;selenium.common.exceptions.InvalidSessionIdeException:消息:无效会话id“;在对表的链接进行爬网时

Python 3.x 获取错误“;selenium.common.exceptions.InvalidSessionIdeException:消息:无效会话id“;在对表的链接进行爬网时,python-3.x,beautifulsoup,selenium-chromedriver,Python 3.x,Beautifulsoup,Selenium Chromedriver,正在尝试爬网表tr td[2]中给出的链接,但遇到以下错误--selenium.common.exceptions.invalidSessionIdeException:消息:会话id无效 我尝试过使用SeleniumWebDriver,但没有发现seesion错误的问题 from bs4 import BeautifulSoup from selenium import webdriver url="https://www.zaubacorp.com/company-

正在尝试爬网表tr td[2]中给出的链接,但遇到以下错误--selenium.common.exceptions.invalidSessionIdeException:消息:会话id无效

我尝试过使用SeleniumWebDriver,但没有发现seesion错误的问题

    from bs4 import BeautifulSoup
    from selenium import webdriver

    url="https://www.zaubacorp.com/company-list"

    driver = webdriver.Chrome(r'C:\chromedriver.exe')
    driver.get(url)

    driver.close()

    soup = BeautifulSoup(driver.page_source,'html.parser')
    table = soup.find('table',{'id':'table'})
    body = table.find('tbody')
    for links in body.find_all('a'):
        print(links['href'])

请帮助我完成此操作。提前谢谢。

在获取页面源代码值之前,您将关闭浏览器,因此selenium无法获取会话。请立即尝试

from bs4 import BeautifulSoup
from selenium import webdriver

url="https://www.zaubacorp.com/company-list"
driver = webdriver.Chrome(r'C:\chromedriver.exe')
driver.get(url)
soup = BeautifulSoup(driver.page_source,'html.parser')
driver.close()
table = soup.find('table',{'id':'table'})
body = table.find('tbody')
for links in body.find_all('a'):
 print(links['href'])