Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

SyntaxError: invalid syntax in For Loop in python jupyter notebook

$
0
0
from splinter import Browserfrom bs4 import BeautifulSoup as soupbrowser = Browser('chrome')url = 'https://static.bc-edx.com/data/web/mars_news/index.html'browser.visit(url)html = browser.htmlsoup = soup(html, 'html.parser')text_info = soup.find_all(class_ = "list_text")content_list = []For each in text_info: <-- Error occurs here    # Extract the title    content_title = each.find(class_ = "content-title").text.strip()    # Extract the preview text    preview_text = each.find(class_ = "article_teaser_body").text.strip()    # Store each title and preview pair in a dictionary    content_dict = {"title": content_title,"preview": preview_text    }    # Add the dictionary to the list    content_list.append(content_dict)

ERROR:

Cell In[8], line 5    For each in text_info:        ^SyntaxError: invalid syntax

Any help explaining this error or any advice on how to fix this issue would be much appreciated!


Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>