beautiful soup find text code example
Example 1: beautifulsoup find all class
mydivs = soup.findAll("div", {"class": "stylelistrow"})
Example 2: beautifulsoup get text
page = soup.find('p').getText()
Example 3: beautifulsoup find by text
soup.find_all("a", string="Elsie")
Example 4: python beautifulsoup get attibute
xmlData = None
with open('conf//test1.xml', 'r') as xmlFile:
xmlData = xmlFile.read()
xmlDecoded = xmlData
xmlSoup = BeautifulSoup(xmlData, 'html.parser')
repElemList = xmlSoup.find_all('repeatingelement')
for repElem in repElemList:
print("Processing repElem...")
repElemID = repElem.get('id')
repElemName = repElem.get('name')
print("Attribute id = %s" % repElemID)
print("Attribute name = %s" % repElemName)