1

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?

0

2 Answers 2

2

You need to import pprint() function from pprint module.

Replace:

import pprint

with:

from pprint import pprint
Sign up to request clarification or add additional context in comments.

1 Comment

Augh, so simple! I just got so tunnel visioned on the beautifulsoup module Thank you.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.