使用beautifulsoup4提取标题标签元素

艾尼什

想要提取标题中提到的评论评级弹出评级百分比。这里给出了 html:

    a class="a-link-normal" href="http://www.amazon.in/product-reviews/B01FM7GGFI/ref=cm_cr_dp_hist_one/261-4285111-5015802?ie=UTF8&amp;filterByStar=one_star&amp;reviewerType=all_reviews&amp;showViewpoints=0" title="11% of reviews have 1 stars">1 star</a>

beautifulsoup python 脚本:

     from bs4 import BeautifulSoup
     import requests
     url = "http://www.amazon.in/Samsung-G-550FY-On5-Pro-Gold/dp/B01FM7GGFI/ref=lp_4363159031_1_1/261-4285111-5015802?s=electronics&ie=UTF8&qid=1503582445&sr=1-1"

    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'}
    r = requests.get(url, headers=headers)
     soup = BeautifulSoup(r.content, "lxml")

    for link in soup.find_all("div", attrs={"class": "a-fixed-left-grid-col a-col-left"}):
      for link1 in link.find_all("a", attrs={"class": "a-link-normal"}):
         print(link1)
德米特里·菲亚尔科夫斯基
html = '<a class="a-link-normal" href="http://www.amazon.in/product-reviews/B01FM7GGFI/ref=cm_cr_dp_hist_one/261-4285111-5015802?ie=UTF8&amp;filterByStar=one_star&amp;reviewerType=all_reviews&amp;showViewpoints=0" title="11% of reviews have 1 stars">1 star</a>'
soup = BeautifulSoup(html, 'lxml')

a_tags = soup.find_all('a', class_='a-link-normal')
for a in a_tags:
    if 'title' in a.attrs:
        print(a['title'])

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用 BeautifulSoup4 提取 XML 标签中的属性

从<script>标签BeautifulSoup4中提取令牌,请求

提取标签attr'data-title'beautifulsoup4

BeautifulSoup4 不能只从标签中提取文本

BeautifulSoup4遗失标签

如何使用 BeautifulSoup4 和请求获取标题的内容

使用beautifulsoup4从网站提取数据并解析成csv

使用beautifulsoup4,Python在html标签内查找链接

使用BeautifulSoup4在Python中存储标签中的数据

使用 Python 抓取 HTML 中的特定元素:BeautifulSoup4

使用BeautifulSoup提取标题

BeautifulSoup4:提取表格,现在如何排除某些我不想要的标签和信息位

BeautifulSoup4:如何按类提取标签但忽略后面的所有属性

如何使用 Beautifulsoup4

使用BeautifulSoup提取链接的标题

如何使用beautifulsoup4从网页中仅提取特定类型的链接

如何使用beautifulsoup4在python中的pre标签中获取文本?

如何使用BeautifulSoup4从客户标签中抓取信息

使用beautifulsoup4在基于同级的两个相同标签内容之间进行区分

使用Python中的BeautifulSoup 4从div标签中提取文本

使用BeautifulSoup提取<span> WITH标签

如何安装和使用beautifulsoup4

使用BeautifulSoup4解析数据

使用Beautifulsoup4从HTML剥离Doctype?

无法使用BeautifulSoup4抓取网站

使用BeautifulSoup4解析网页

使用BeautifulSoup4从CSS3伪元素获取内容

如何使用Beautifulsoup4刮除属性中未指定类或ID的HTML元素

Python-使用BeautifulSoup4获取父元素的第一个孩子