У меня есть проблема с моими скачанными html файлами для анализа в соответствующем формате. В div DIV id = article_participants class = "content_part hid" указаны имена руководителей (например, как показано ниже: Дрор Бен Ашер, Ори Шило и Гай Гольдберг). настройки div и html одинаковы.
<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>
<p>Scott Henry - Roth Capital</p>
</div>
Позже в html (в DIV id = article_qanda class = "content_part hid") руководители отвечают на вопросы. Эти ответы (должны быть распознаны <P><STRONG><SPAN class=answer>Ori Shilo</SPAN></STRONG></P>
В Dropbox я поделился примером одного из загруженных мной htmls: https://www.dropbox.com/s/uka24w7o5006ole/transcript-86-855.html?dl=0
То, что я должен сделать, это следующее (для всех моих файлов в каталоге в одном файле CSV): Руководители /// Ответы /// заголовок html
Мой код до сих пор только для одного руководителя:
import textwrap
import os
from bs4 import BeautifulSoup
directory ='C:/Research syntheses - Meta analysis/SeekingAlpha/'
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')
print('{:<30} {:<70}'.format('Name', 'Answer'))
print('-' * 101)
def find_executive(soup, executive):
for answer in soup.select(f'p:contains("Question-and-Answer Session") ~ strong:contains({executive}) + p'):
txt = answer.get_text(strip=True)
s = answer.find_next_sibling()
while s:
if s.name == 'strong' or s.find('strong'):
break
if s.name == 'p':
txt += ' ' + s.get_text(strip=True)
s = s.find_next_sibling()
txt = ('\n' + ' '*31).join(textwrap.wrap(txt))
print('{:<30} {:<70}'.format(func, txt), file=open("output.txt", "a"))
Может ли кто-нибудь помочь мне в решении этой проблемы?