【发布时间】:2020-04-22 16:36:33
【问题描述】:
我正在尝试通过 br 标签分割文本。
我有这个标签:
<div class="grseq"><p class="tigrseq"><span id="id0-I."></span>Section I: Contracting authority</p><div class="mlioccur"><span style="color:black" class="nomark"><!--Non empty span 2-->I.1)</span><span class="timark" style="font-weight:bold;color:black;">Name and addresses</span><div style="color:black" class="txtmark">Official name: WOBA mbH Oranienburg<br>Postal address: Villacher Straße 2<br>Town: Oranienburg<br>NUTS code: <span class="nutsCode" title="Oberhavel">DE40A</span><br>Postal code: 16515<br>Country: Germany<br>E-mail: <a class="ojsmailto" href="mailto:kordecki@woba.de?subject=TED">kordecki@woba.de</a><p><b>Internet address(es): </b></p><p>Main address: <a class="ojshref" href="http://www.woba.de" target="_blank">www.woba.de</a></p></div><!--//txtmark end--></div><div class="mlioccur"><span style="color:black" class="nomark"><!--Non empty span 2-->I.2)</span><span class="timark" style="font-weight:bold;color:black;">Information about joint procurement</span></div><div class="mlioccur"><span style="color:black" class="nomark"><!--Non empty span 2-->I.4)</span><span class="timark" style="font-weight:bold;color:black;">Type of the contracting authority</span><div style="color:black" class="txtmark">Other type: Wohnungswirtschaft</div><!--//txtmark end--></div><div class="mlioccur"><span style="color:black" class="nomark"><!--Non empty span 2-->I.5)</span><span class="timark" style="font-weight:bold;color:black;">Main activity</span><div style="color:black" class="txtmark">Housing and community amenities</div><!--//txtmark end--></div></div>
我尝试像这样接收每一行的列表:
['Official name: WOBA mbH Oranienburg', 'Postal address: Villacher Straße 2', ...]
这是我的代码:
webpage = 'https://ted.europa.eu/udl?uri=TED:NOTICE:565570-2019:TEXT:EN:HTML&src=0&tabId=0#id1-I.'
webpage_response = requests.get(webpage)
soup = BeautifulSoup(webpage_response.content, 'lxml')
tags = soup.find(class_="mlioccur")
br_tags = tags.text.strip().split('\n\n')
print(br_tags)
我收到的是一个包含一个条目的列表:
['I.1)Name and addressesOfficial name: WOBA mbH OranienburgPostal address: Villacher Straße 2Town: OranienburgNUTS code: DE40APostal code: 16515Country: GermanyE-mail: kordecki@woba.deInternet address(es): Main address: www.woba.de']
如果有任何帮助将不胜感激:)
【问题讨论】:
标签: python-3.x text beautifulsoup split tags