keshr3106
keshr3106

Reputation: 413

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.

Upvotes: 12

Views: 24989

Answers (1)

Guy Gavriely
Guy Gavriely

Reputation: 11396

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

or:

[row.text for row in rows]

Upvotes: 20

Related Questions