解析HTML时出错

2024-10-03 21:33:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在有一个很大的HTML文件,里面装满了目录,我必须解析和提取姓名、地址、邮政编码、电话号码、备用电话号码等,然后将内容放入数组中。其中一些目录列表(如下面所示的代码片段)不那么具有挑战性,而且解析起来也很简单。你知道吗

<span style="font-family: b'CUQZKJ+GaramondPremrPro-LtDisp'; font-size:12px">Aletheia House
<br>201 Finley Avenue West
<br>Birmingham, AL 35204
<br>(205) 324-6502x22
<br>Intake: (205) 324-6502
</span>

样本数组输出

["Aletheia House", "201 Finley Avenue West",
 "Birmingham, AL 35204", "(205) 324-6502x22", "Intake: (205) 324-6502"]

然而,对于下面的代码片段这样的场景,我目前面临的问题是如何使用BeautifulSoup、Python和RegEx解析场景。你知道吗

<span style="font-family: b'CUQZKJ+GaramondPremrPro-LtDisp'; font-size:12px">Alcohol and Drug Abuse
<br>Treatment Centers Inc/Pearson Hall
<br>2701 Jefferson Avenue SW
<br>Birmingham, AL 35211
<br>(205) 923-6552x12
<br>Intakes: (205) 923-6552x10 (205) 923-
<br>6552x13
</span>

样本数组输出:

["Alcohol and Drug Abuse Treatment Centers Inc/Pearson Hall", 
 "2701 Jefferson Avenue SW", "Birmingham, AL 35211", "(205) 923-6552x12",
 "Intakes: (205) 923-6552x10 (205) 923-6552x13"]

谢谢你!你知道吗


Tags: 代码br目录style电话号码数组familyspan