selenium geckodriver:Tried to run command without establishing a connection解决
selenium.common.exceptions.InvalidSessionIdException: Message: Tried to run command without establishing a connection去掉browser.close()即可import timefrom selenium.common.exceptions import TimeoutExce...
·
selenium.common.exceptions.InvalidSessionIdException: Message: Tried to run command without establishing a connection
去掉browser.close()即可
import time
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
from requests.exceptions import RequestException
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import html2text
path=r'D:\tmp\true07.txt'
UrlList=[]
browser = webdriver.Firefox(executable_path=r'G:\chromediver\geckodriver.exe')
with open(path,'r',errors='replace') as f:
txt=f.readlines()
for line in txt:
UrlList.append(line)
for url in UrlList:
print(url)
browser.get(url)
time.sleep(10)
# wait = WebDriverWait(browser, 10)
# #在 10 秒内如果节点成功加载出来,就返回该
# # 节点;如果超过 10 秒还没有加载出来,就抛出异常
# button = wait.until(EC.element_to_be_clickable((By.TAG_NAME, 'a')))
# button.click()
with open(r'D:\tmp\all01.txt','a',encoding='utf-8') as f0:
f0.write(html2text.html2text(browser.page_source))
# browser.close()
print('next')
更多推荐



所有评论(0)