您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python:BeautifulSoup通过其类提取div标签之间的字符串

5b51 2022/1/14 8:22:51 python 字数 1553 阅读 563 来源 www.jb51.cc/python

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' c

概述

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标签得到它们.

关于如何单独提取文本,我需要帮助.我需要单独的文本 – 在div类标签之间.

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

要么:

[row.text for row in rows]

总结

以上是编程之家为你收集整理的Python:BeautifulSoup通过其类提取div标签之间的字符串全部内容,希望文章能够帮你解决Python:BeautifulSoup通过其类提取div标签之间的字符串所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶