I am trying to use a CSS selector on a specific tag on the webpage's source. This is what I have right now:
from bs4 import BeautifulSoup
import requests
import pprint
r2 = requests.get("http://spot311.calgary.ca/reports/15-00462387")
soup = BeautifulSoup(r2.text, 'html.parser')
pprint(soup.select("blockquote"))
On the page source, there is only one tag called "blockquote", but I am getting the error:
pprint(soup.select("blockquote"))
TypeError: 'module' object is not callable
I googled around and turned up some people having issues where they only wrote
import BeautifulSoup
instead of
from BeautifulSoup import BeautifulSoup
But I already have
from bs4 import BeautifulSoup
which is correct for my python distribution, I know because I have another program that uses this import and it works just fine.
Am I just not using the selector right?
2 Answers 2
You need to import pprint() function from pprint module.
Replace:
import pprint
with:
from pprint import pprint
1 Comment
No, you can leave it as
import pprint
but when you call for it later you must write
pprint.pprint((soup.select("blockquote"))
In my beginner opinion, i think this is better formatting as it is clearer to see later on in big projects what module that function came from.