I'm using selenium. Normally it's working fine but some times it shows the below error :
Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
(Session info: headless chrome=78.0.3904.70)
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.4.0-1029-aws x86_64)
Here is my code :
from flask import Flask, render_template
from selenium import webdriver
app = Flask(__name__)
app.config["DEBUG"] = True
def getInformation(driver, url):
driver.get(url)
res = BeautifulSoup(driver.page_source, 'html.parser')
info = res.find(class_="category_title pcol2")
return info
@app.route("/", methods=["GET", "POST"])
def init():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument(
"'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'")
driver = webdriver.Chrome(options=chrome_options)
url = "https://blog.naver.com"
ret = getInformation(driver, url)
driver.quit()
return render_template("checkresult.html", ret=ret)
What's the wrong with my code? and How can I avoid the exception?