【发布时间】:2012-06-12 01:34:05
【问题描述】:
我是第一次使用 Python,我使用 Mechanize 搜索网站以及 BeautifulSoup 来选择特定的 div,现在我正在尝试使用正则表达式获取特定的句子。这是汤对象的内容;
<div id="results">
<table cellspacing="0" width="100%">
<tr>
<th align="left" valign="middle" width="32%">Physician Name, (CPSO#)</th>
<th align="left" valign="middle" width="36%">Primary Practice Location</th>
<!-- <th width="16%" align="center" valign="middle">Accepting New Patients?</th> -->
<th align="center" valign="middle" width="32%">Disciplinary Info & Restrictions</th>
</tr>
<tr>
<td>
<a class="doctor" href="details.aspx?view=1&id= 85956">Hull, Christopher Merritt </a> (#85956)
</td>
<td>Four Counties Medical Clinic<br/>1824 Concessions Dr<br/>Newbury ON N0L 1Z0<br/>Phone: (519) 693-0350<br/>Fax: (519) 693-0083</td>
<!-- <td></td> -->
<td align="center"></td>
</tr>
</table>
</div>
(感谢您在格式化方面的帮助)
我获取文本“Hull, Christopher Merritt”的正则表达式是;
patFinderName = re.compile('<a class="doctor" href="details.aspx?view=1&id= 85956">(.*) </a>')
它总是返回空,我不知道为什么,有人有什么想法吗?
感谢您的回答,我已将其更改为;
patFinderName = re.compile('<a class="doctor" href=".*">(.*) </a>')
现在效果很好。
【问题讨论】:
-
你需要在
aspx之后转义?。
标签: python beautifulsoup mechanize