Python Forum
can't assign to operator - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: can't assign to operator (/thread-25843.html)



can't assign to operator - Calli - Apr-13-2020

I am trying to scrap this jokes from the website but i get the assignment operator error
from urllib.requests import urlopen as uReq
from bs4 import BeautifulSoup as soup 

quotes_page = 'http://www.laughfactory.com/jokes/yo-momma-jokes'

uClient = uReq(quotes_page)
page_html = uClient.read()
uClient.close()

page_soup = soup(page_html, "html.parser")
quotes = page_soup.findAll("div",{"class":"jokes"})

for quote in quotes:
	fav_quote = quote.findAll("div",{"class":"joke-msg"})
	joke-msg = fav_quote[0].text.stip()

	fav_authors = quote.findAll("div",{"class":"joke-text"})
	joke-text = fav_authors[0].text.strip()

	print (joke-msg)
	print (joke-text)
Error messsage
  File "yomama.py", line 17
    joke-msg = fav_quote[0].text.stip()
    ^
SyntaxError: can't assign to operator



RE: can't assign to operator - buran - Apr-13-2020

please, post the full traceback you get in error tgs


RE: can't assign to operator - micseydel - Apr-14-2020

Variables can't have a dash in them. You can use underscores instead though.