Saturday, November 9, 2013

Python: Get div content using BeautifulSoup

I am going to show you an example that will parse a div content from the given html. Lets consider the python variable content holds the html source in it.


soup = BeautifulSoup(content)
div_content = soup.find("div", {"class": "product"})
print div_content
print str(div_content)


In this example, the code is basically parsing the div tags which are only having the class=product. You can add more attributes like id=... and so on. For example,

div_content = soup.find("div", {"class": "product", "id": "myDiv"})



No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...