2024-10-01 19:25:04 发布
网友
如何提取html文件的特定部分示例https://patents.google.com/patent/EP1208209A1/en?oq=medicinal+chemistry
到目前为止,我使用beautifulsoup获取html的文本版本,而不包含所有标记。但是我希望我的代码只读上面提到的文件的索赔部分
filename= 'C:/Users/xyz/.ipynb_checkpoints/EP1208209A1.html' html_file =open(filename, 'r', encoding='utf-8') source_code = html_file.read() #print(source_code) soup = BeautifulSoup(source_code) print(soup.get_text()) #mydivs = soup.findAll("div", {"class": "flex flex-width style-scope patent-result"}) #div_with_claims = mydivs [1] #print(div_with_claims)
据我所知,有两个div和^{cl1}$
soup = BeautifulSoup(sdata) mydivs = soup.findAll("div", {"class": "flex flex-width style-scope patent-result"}) div_with_claims = mydivs [1]
这里有mate,我发现在这个站点中,索赔部分是一个带有自己Id的html,使事情变得更简单。我只是把这一部分整理好,给你一根绳子,你就可以玩了
import requests from bs4 import BeautifulSoup page = requests.get("https://patents.google.com/patent/EP1208209A1/en?oq=medicinal+chemistry") soup = BeautifulSoup(page.content, 'html.parser') claim_sect = soup.find_all('section', attrs={"itemprop":"claims"}) print('This is the raw content: \n') print(str(claim_sect)) print('This is the variable type: \n') print(str(type(claim_sect))) str_sect = claim_sect[0]
据我所知,有两个div和^{cl1}$
这里有mate,我发现在这个站点中,索赔部分是一个带有自己Id的html,使事情变得更简单。我只是把这一部分整理好,给你一根绳子,你就可以玩了
相关问题 更多 >
编程相关推荐