Python:BeautifulSoup按其类提取div标签之间的字符串 [英] Python: BeautifulSoup extract string between div tag by its class
本文介绍了Python:BeautifulSoup按其类提取div标签之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
此代码用于从网站中提取评论.我只需要 文本-但是我可以通过div标签获得它们.
This code is used to extract the reviews from the website. I need only the text - but I get them with the div tags.
我需要有关如何单独提取文本的帮助.我只需要div类标记之间的文本即可.
I need help regarding how the text alone gets extracted. I require the text alone-between the div class tags.
推荐答案
for row in soup.find_all('div',attrs={"class" : "reviewText"}):
print row.text
或:
[row.text for row in rows]
这篇关于Python:BeautifulSoup按其类提取div标签之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文