Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正则表达式在Python中不返回任何内容_Python_Beautifulsoup_Mechanize - Fatal编程技术网

正则表达式在Python中不返回任何内容

正则表达式在Python中不返回任何内容,python,beautifulsoup,mechanize,Python,Beautifulsoup,Mechanize,我第一次使用Python,我使用Mechanize和BeautifulSoup搜索了一个网站,以选择一个特定的div,现在我尝试用正则表达式获取一个特定的句子。这是汤对象的内容 <div id="results"> <table cellspacing="0" width="100%"> <tr> <th align="left" valign="middle" width="32%">Physician Na

我第一次使用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  &amp; Restrictions</th>
     </tr>

    <tr>
        <td>
            <a class="doctor" href="details.aspx?view=1&amp;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>

医生姓名(CPSO)
主要实习地点
纪律资料及;限制
(#85956)
四县医疗诊所N0L 1Z0上的1824名医生电话:(519)693-0350
传真:(519)693-0083
(感谢您对格式设置的帮助)

我得到文本“Hull,Christopher Merritt”的正则表达式是

patFinderName=re.compile(“”)
它一直空着,我不明白为什么,有人有什么想法吗

谢谢你的回答,我把它改成了

patFinderName = re.compile('<a class="doctor" href=".*">(.*) </a>')
patFinderName=re.compile(“”)

现在它工作得很好。

是正则表达式中的一个神奇标记,表示前一个原子的零或一。当您想要一个文字问号符号时,您需要将其转义。

是正则表达式中的一个神奇标记,表示零或前一个原子中的一个。由于您需要文字问号符号,因此需要将其转义。

您应该转义正则表达式中的

In [8]: re.findall('<a class="doctor" href="details.aspx\?view=1&amp;id= 85956">(.*)</a>', text)
Out[8]: ['Hull, Christopher Merritt ']
[8]中的
:关于findall(“”,text)
出[8]:['Hull,Christopher Merritt']

您应该在正则表达式中转义

In [8]: re.findall('<a class="doctor" href="details.aspx\?view=1&amp;id= 85956">(.*)</a>', text)
Out[8]: ['Hull, Christopher Merritt ']
[8]中的
:关于findall(“”,text)
出[8]:['Hull,Christopher Merritt']

您需要在
aspx
之后转义
。可能重复,并且可能需要在
aspx
之后转义
。可能重复,并且可能啊,我不知道。谢谢你,我对正则表达式还不熟悉,我甚至没有想到过类似的事情。啊,我不知道。谢谢你,我对正则表达式还不太熟悉,类似的事情我都没想过。两个答案都很好,但他首先回答说:对不起。谢谢你的格式帮助。@user1094705是的,我正在编辑你的帖子,而其他人正在回答你的问题。两个答案都很好,但他先回答了,对不起。谢谢你的格式帮助。@user1094705是的,我正在编辑你的文章,而其他人正在回答你的问题。