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

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?

+4
source share
1 answer

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

+6
source

Source: https://habr.com/ru/post/1491250/


All Articles