I'm trying to scrape the time of the next upcoming game from ESPN, as you can find on ESPN: https://www.espn.com/ (right now it appears to be a soccer match between Juventus and AC Milan)
I have the following python code for my webscrape:
import requests
from lxml import html
from selenium import webdriver
import chromedriver_binary
driver = webdriver.Chrome()
driver.get('https://www.espn.com/')
tree = html.fromstring(driver.page_source)
time = tree.xpath('//*[@id="news-feed"]/section[1]/header/a/div[2]/span[2]/span')
print(time)
but it returns this error:
Traceback (most recent call last):
File "c:\Users\akash\Coding\test\scrape.py", line 9, in <module>
tree = html.fromstring(driver.page_source)
File "C:\Users\akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 679, in page_source
return self.execute(Command.GET_PAGE_SOURCE)['value']
File "C:\Users\akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=83.0.4103.97)
I suspect the problem is because this is dynamic content on the ESPN website, because I was able to scrape data from another website with constant data, using the same code (except changing the URL and XPath). Could anyone help fix this error?
I've already installed each of the python libraries in the code. (Note: I've already looked at Scraping using python and xpath and Python Selenium Chrome Webdriver)