I'm following a tutorial to create a bot that can perform tasks on any web page. I am using Python3 to search any random website, then using the search results (from that site) to print data. I have imported a selenium webdriver, and have ensured that it is set up correctly.
The problem i'm facing is i'm trying to create a for loop that cycles through search results. This for loop is using the class name from the website i'm testing - so the bot can identify article elements. The issue is the class name is: c-entry-box--compact__title
This is causing
SyntaxError: Cannot assign to literal
Is there any way around this? This websites' search results doesn't have any other shorter class names or ids that are shorter, nor does it contain hyphens or underscores. I am running my code on test website 'theverge's' search results.
Relevant code:
try:
main = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "c-entry-box--compact__body"))
)
articles = main.find_element_by_class_name("c-entry-box--compact__title")
for "c-entry-box--compact__title" in articles:
header = articles.find_element_by_class_name("c-entry-box--compact__title")
print(header.text)
finally:
driver.quit()
Any tips or ideas to point me in the right direction is greatly appreciated!
Update: 11:44pm 21/8
I created a variable for the class name. Now the error is
...line 28, in <module>
for article in articles:
TypeError: 'WebElement' object is not iterable
Update 12:12am 22/8
I made the recent posters changes and tweaked some of my code. The only error i get now is to do with the use of keyboard entries, or keys. It is a AttributeError: 'list' object has no attribute 'send_keys'
My code is
search_button = driver.find_elements_by_id("icon-search")
search = driver.find_elements_by_name("q")
search.send_keys('facebook')
search.send_keys(Keys.RETURN)