BeautifulSoup: print(s.find_all(class="title")) SyntaxError: invalid syntax

python

Solution

`class` is a keyword in python. Use `find_all('p', { 'class' : "title"})` or `find_all(class_="title")` instead.

Problem

Script: ``` #!/usr/bin/python3.2 from bs4 import BeautifulSoup as bs content = '<p class="title">hello world</p>' s = bs(content) print(s.find_all(class="title")) ``` Output: ``` File "bs.py", line 7 print(s.find_all(class="title")) ^ SyntaxError: invalid syntax ``` BS Docs: ``` soup.find_all(id="link2") # [<a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>] ``` Question: Why is there a syntax error?

Original source