我已经部署了执行一些抓取操作的flask应用程序。它在本地计算机上运行正常,但是当我将其部署到Heroku时,问题开始了。一段时间后,剪贴画停止,并显示错误selenium.common.exceptions.InvalidSessionIdException:消息:无效的会话ID。我将如何在heroku上解决这个问题。
错误
2020-10-07T04:02:26.091251 + 00:00 app [web.1]:追溯(最新 最后调用):2020-10-07T04:02:26.091308 + 00:00 app [web.1]:文件 “ main.py”,第231行,在2020-10-07T04:02:26.091612 + 00:00 app [web.1]:如果len(obj.browser.window_handles)> 1: 2020-10-07T04:02:26.091613 + 00:00 app [web.1]:文件 “ /app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py”, 第724行,在window_handles 2020-10-07T04:02:26.091971 + 00:00 app [web.1]:返回 self.execute(Command.W3C_GET_WINDOW_HANDLES)['值'] 2020-10-07T04:02:26.091972 + 00:00 app [web.1]:文件 “ /app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py”, 第321行,在执行2020-10-07T04:02:26.092205 + 00:00 app [web.1]: self.error_handler.check_response(响应) 2020-10-07T04:02:26.092210 + 00:00 app [web.1]:文件 “ /app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py”, 第242行,在check_response 2020-10-07T04:02:26.092437 + 00:00 app [web.1]:引发exception_class(消息,屏幕,堆栈跟踪) 2020-10-07T04:02:26.092477 + 00:00 app [web.1]: selenium.common.exceptions.InvalidSessionIdException:消息:无效 会话ID
代码
obj = EstimateScrapper()
current_session = obj.browser.session_id
print(current_session)
count = 0
print("Initializing Process")
rows = in_excel.worksheet.max_row
for row in range(2, rows):
status = str(in_excel.read_cell(row, 'P'))
if status != '1':
count += 1
if len(obj.browser.window_handles) > 1:
obj.browser.quit()
obj = EstimateScrapper()
address = in_excel.read_cell(row, 'C')
city = in_excel.read_cell(row, 'D')
print(row, '=>', address, city)
data = obj.RUN(address, city)
in_excel.write_cell(row, 'G', data['redfin'])
in_excel.write_cell(row, 'H', data['trulia'])
in_excel.write_cell(row, 'J', data['remax'])
in_excel.write_cell(row, 'K', data['homes'])
in_excel.write_cell(row, 'N', data['mean'])
in_excel.write_cell(row, 'O', data['new'])
in_excel.write_cell(row, 'P', 1)
in_excel.save_workbook()
obj.browser.quit()
如果所有这些都是由于会话ID而发生的,我将如何解决这个问题,以便刮板不会在heroku上停止