I am execute following code to connect to Hacker News
def connect_to_base(browser, page_number):
base_url = f"https://news.ycombinator.com/news?p={page_number}"
connection_attempts = 0
while connection_attempts < 3:
try:
browser.get(base_url)
# wait for table element with id = 'hnmain' to load
# before returning True
WebDriverWait(browser, 5).until(
EC.presence_of_element_located((By.ID, "hnmain"))
)
return True
except Exception as e:
print(e)
connection_attempts += 1
print(f"Error connecting to {base_url}.")
print(f"Attempt #{connection_attempts}.")
return False
When I run the above script, I am getting the following error:
NameError: name 'hnmain' is not defined
I'm having trouble figuring out why it's saying 'hnmain' is undefined because 'hnmain' is just an ID of a webelement element in the website.
Do I need to parse it another way?