我用python编写了一个脚本,从html元素块中提取地址。地址在两个br
标记内。然而,当我运行我的脚本时,我得到这个[<br/>, <br/>, <br/>, <br/>]
作为输出
我怎样才能得到完整的地址
我试图从中收集地址的html元素:
<div class="ACA_TabRow ACA_FLeft">
Mailing
<br/>
1961 MAIN ST #186
<br/>
WATSONVILLE, CA, 95076
<br/>
United States
<br/>
</div>
我已经试过了:
from bs4 import BeautifulSoup
import re
html = """
<div class="ACA_TabRow ACA_FLeft">
Mailing
<br/>
1961 MAIN ST #186
<br/>
WATSONVILLE, CA, 95076
<br/>
United States
<br/>
</div>
"""
soup = BeautifulSoup(html,"lxml")
items = soup.find(class_="ACA_TabRow").find(string=re.compile("Mailing")).find_next_siblings()
print(items)
输出:
我将继续检查div startswith
Mailing
中的stripped字符串输出
看来我找到了更好的解决办法:
输出:
相关问题 更多 >
编程相关推荐