BeautifulSoup getting href

I have the following soup: From this I want to extract the href, “some_url” I can do it if I only have one tag, but here there are two tags. I can also get the text ‘next’ but that’s not what I want. Also, is there a good description of the API somewhere with examples. … Read more

Using BeautifulSoup to search HTML for string

The following line is looking for the exact NavigableString ‘Python’: Note that the following NavigableString is found: Note this behaviour: So your regexp is looking for an occurrence of ‘Python’ not the exact match to the NavigableString ‘Python’.

ImportError: No Module Named bs4 (BeautifulSoup)

Activate the virtualenv, and then install BeautifulSoup4: When you installed bs4 with easy_install, you installed it system-wide. So your system python can import it, but not your virtualenv python. If you do not need bs4 to be installed in your system python path, uninstall it and keep it in your virtualenv. For more information about virtualenvs, read this

Understand the Find() function in Beautiful Soup

soup.find(“div”, {“class”:”real number”})[‘data-value’] Here you are searching for a div element, but the span has the “real number” class in your example HTML data, try instead: Here we are also checking for presence of data-value attribute. To find elements having “real number” or “fake number” classes, you can make a CSS selector: To get the 69% value: Or, a CSS selector: Or, locating the h6 element … Read more

Where is BeautifulSoup4 hiding?

Try import bs4. It’s unfortunate there’s no correspondence between PyPI package name and import name. After that the class names are the same as before eg. soup = bs4.BeautifulSoup(doc) will work. If that still doesn’t work, try pip install again and note the path to the package install. Then in your python console run import … Read more