beautifulsoup - Get Structured Data from HTML using python and beautiful soup -


I'm new to Python I want to get the result of the code given below:

  score postive negative 5 good bad 7 interesting 3 awesome  

But my code output is nothing.Please look beautiful from BS4 import = "" ... ... lt ; Body & gt; & Lt; Div class = "review" & gt; & Lt; P class = "pos" & gt; there is a problem?

; & Lt; P class = "condition" & gt; Interesting & lt; / P & gt; good; & Lt; / P & gt; & Lt; P square = "neg"; & Lt; / Div & gt; & Lt; Div class = "review" & gt; & Lt; P class = "neg" & gt; Awesome & lt; / P & gt; & Lt; / Div & gt; ... & lt; / Body & gt; Soup = beautiful soup ('P', attrs = {'class': 'pos'}): For the parents ('div', attrs = {'class': 'review'}) in postive ( Text): if parent.findNextSiblings ('p', attrs = {'class': 'pos'}) .append (parent.get_text ()) else: postive.append ("") If parent.findNextSiblings ('p' , Attrs = {'class': 'neg'}): negtive.append (parent.get_text) Other: negtive.append ("")

p tag div class review Children:

  positive = [] negative = [] for div in 'Soup.find_all' ('div', attrs = {'class': 'review'}): pos = div. Find ('p', {'class': 'pos'}) positive.append (pos.get_text () if pos else '') neg = div.f Ind ('p', {'class': 'neg'}) negative.append (neg.get_text () if neg other '') print positive print negative  

print:

  [u'good ', u'interesting', ']] [u'bad', '', u'horrible ']  

Comments