Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: BeautifulSoup extract string between div tag by its class

import urllib, urllib2
from bs4 import BeautifulSoup, Comment
url='http://www.amazon.in/product-reviews/B00CE2LUKQ/ref=cm_cr_pr_top_link_1?ie=UTF8&showViewpoints=0&sortBy=bySubmissionDateDescending'
content = urllib2.urlopen(url).read()
soup = BeautifulSoup(content, "html.parser")
rows =soup.find_all('div',attrs={"class" : "reviewText"})
print rows

This code is used to extract the reviews from the website. I need only the text - but I get them with the div tags.

I need help regarding how the text alone gets extracted. I require the text alone-between the div class tags.

like image 569
keshr3106 Avatar asked Jan 22 '14 17:01

keshr3106


1 Answers

for row in soup.find_all('div',attrs={"class" : "reviewText"}):
    print row.text

or:

[row.text for row in rows]
like image 185
Guy Gavriely Avatar answered Oct 14 '22 04:10

Guy Gavriely