【发布时间】:2020-01-23 13:53:30
【问题描述】:
我有一堆具有相同设置的 HTML 文件。从这些(本地存储的 HTML)中,我想提取黄色标记的字段(example)。 作为文本(只有我感兴趣的 div 部分),可以在 Dropbox 上找到总 html: https://www.dropbox.com/s/uka24w7o5006ole/transcript-86-855.html?dl=0
<DIV id=article_participants class="content_part hid">
<P>Redhill Biopharma Ltd. (NASDAQ:<A title="" href="http://seekingalpha.com/symbol/rdhl" symbolSlug="RDHL">RDHL</A>)</P>
<P>Q4 2014 <SPAN class=transcript-search-span style="BACKGROUND-COLOR: yellow">Earnings</SPAN> Conference <SPAN class=transcript-search-span style="BACKGROUND-COLOR: #f38686">Call</SPAN></P>
<P>February 26, 2015 9:00 AM ET</P>
<P><STRONG>Executives</STRONG></P>
<P>Dror Ben Asher - CEO</P>
<P>Ori Shilo - Deputy CEO, Finance and Operations</P>
<P>Guy Goldberg - Chief Business Officer</P>
<P><STRONG>Analysts</STRONG></P>
我对 Python 了解不多,但我认为使用 Beautiful soup 这应该是双倍的,但我被困住了。 到目前为止我得到的是:
import textwrap
import os
from bs4 import BeautifulSoup
directory ='C:/Research syntheses - Meta analysis/SeekingAlpha/out'
for filename in os.listdir(directory):
if filename.endswith('.html'):
fname = os.path.join(directory,filename)
with open(fname, 'r') as f:
soup = BeautifulSoup(f.read(),'html.parser')
我的输出应该是一个 csv 文件,其中包含: 行政人员姓名/行政人员职能/代码代码/期间
【问题讨论】:
-
你能把输入的html文件分享为文本而不是图像吗?
-
@Alderven 完成。