【问题标题】:Extract a specific header from HTML using beautiful soup使用漂亮的汤从 HTML 中提取特定的标题
【发布时间】:2020-09-07 02:05:37
【问题描述】:

这是我使用的专利示例 https://patents.google.com/patent/EP1208209A1/en?oq=medicinal+chemistry 。下面是我使用的代码。我希望代码仅显示被引用的 (3) 计数,这样我就知道该专利被引用了多少次。如何让输出仅显示被引用的计数为 3?请帮忙!

 
soup = BeautifulSoup(patent, 'html.parser')
cited_section =soup.findAll({"h2":"Cited By"})

print(cited_section)
Output I get is [<h2>Info</h2>, <h2>Links</h2>, <h2>Images</h2>, <h2>Classifications</h2>, <h2>Abstract</h2>, <h2>Description</h2>, <h2>Claims (<span itemprop="count">57</span>)</h2>, <h2>Priority Applications (5)</h2>, <h2>Applications Claiming Priority (1)</h2>, <h2>Related Parent Applications (1)</h2>, <h2>Publications (2)</h2>, <h2>ID=38925605</h2>, <h2>Family Applications (1)</h2>, <h2>Country Status (1)</h2>, <h2>Cited By (3)</h2>, <h2>Families Citing this family (12)</h2>, <h2>Citations (306)</h2>, <h2>Patent Citations (348)</h2>, <h2>Non-Patent Citations (23)</h2>, <h2>Cited By (4)</h2>, <h2>Also Published As</h2>, <h2>Similar Documents</h2>, <h2>Legal Events</h2>]````

【问题讨论】:

  • 页面好像是异步渲染的。我建议你使用Selenium

标签: python html parsing beautifulsoup extract


【解决方案1】:

引用次数是通过 JavaScript 动态创建的。但是您可以使用itemprop="forwardReferencesFamily" 计算元素的数量以获取计数。例如:

import requests
from bs4 import BeautifulSoup


url = 'https://patents.google.com/patent/EP1208209A1/en?oq=medicinal+chemistry'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')

print(len(soup.select('tr[itemprop="forwardReferencesFamily"]')))

打印:

4

【讨论】:

  • 您好,在 html 文件中关注相同的主题,我想从 HTML 标记中找到专利号、引文标题。我试过了,但它会打印 HTML 文件中的所有标题。 html_file =open(filename, 'r', encoding='utf-8') # Opening file in read mode patent = html_file.read() #print(patent) total=0 soup = BeautifulSoup(patent, 'html.parser') x=soup.select('tr[itemprop="backwardReferences"]') y=soup.select('td[itemprop="title"]') print(y)
  • @astronaut 我建议在 SO 上打开一个新问题,在这里您描述问题+您尝试过什么。我会试着看看它。
  • stackoverflow.com/questions/67270690/… 这是新的讨论。我尝试了采用 HTML 标签 'tr[itemprop="backwardReferencesFamily"]' 的方法,但我无法让它在此标签下仅打印标题和出版物编号。我认为这是所有专利中唯一常见的 HTML 标签。其他任何事情都可能不是一致的模式。
【解决方案2】:

您好,在此链接https://patents.google.com/patent/WO2012061469A3/en?oq=medicinal+chemistry 我想要打印专利引用的代码,该引用应该给出公开号、标题。然后我想使用 pandas 将出版物编号放在一列中,将标题放在另一列中。 到目前为止,我已经使用漂亮的汤将 HTML 文件转换为可读格式。我选择了反向引用 HTML 标记,并在该标记下打印引用的出版物编号和标题。我举了一个例子,但我有一个文件夹,里面装满了 HTML 文件,我稍后会做。

x=soup.select('tr[itemprop="backwardReferences"]') 
y=soup.select('td[itemprop="title"]') # this line gives all the titles in the document not particularly under the patent citations
print(y)

【讨论】:

    猜你喜欢
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    相关资源
    最近更新 更多