我正在Python中第一次工作,我已經使用Mechanize搜索一個網站以及BeautifulSoup來選擇特定的div,現在我試圖抓住一個特定的句子,表達。這是湯物的內容;正則表達式在Python中沒有返回任何東西
<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>
(感謝您與格式幫助)
我的正則表達式來獲取文本「赫爾,克里斯托弗·梅里特」的;
patFinderName = re.compile('<a class="doctor" href="details.aspx?view=1&id= 85956">(.*) </a>')
它一直返回空,我不明白爲什麼,有人有任何想法?
謝謝你的答案,我已經改變了;
patFinderName = re.compile('<a class="doctor" href=".*">(.*) </a>')
現在它工作得很好。
你需要躲避'''後aspx'? –
[用於HTML解析的Python正則表達式(BeautifulSoup)](http://stackoverflow.com/q/55391/),[Python Reg Ex。問題](http://stackoverflow.com/q/90052/),並可能[其他](http://stackoverflow.com/search?q=%2Bbeautifulsoup+%2Bfind+%2Belement&submit=search) – outis