Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.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
在python3中进行抓取时,Python请求不返回电子邮件地址_Python_Web Scraping - Fatal编程技术网

在python3中进行抓取时,Python请求不返回电子邮件地址

在python3中进行抓取时,Python请求不返回电子邮件地址,python,web-scraping,Python,Web Scraping,我正试图从下面的URL中删除电子邮件地址 myurl="https://www.charitychoice.co.uk/alzheimers-research-uk" agent = {'User-Agent': 'Magic Browser'} req1 = requests.get(myurl, headers=agent, verify=False) soup2 = BeautifulSoup(req1.content, "lxml") for email in soup2.findAl

我正试图从下面的URL中删除电子邮件地址

myurl="https://www.charitychoice.co.uk/alzheimers-research-uk"
agent = {'User-Agent': 'Magic Browser'}
req1 = requests.get(myurl, headers=agent, verify=False)
soup2 = BeautifulSoup(req1.content, "lxml")

for email in soup2.findAll('div', {"class": "charity-contact-details"}):
        for email1 in email.findAll('p'):
            for email2 in email1.findAll('span', {"itemprop": "email"}):
                for email3 in email2.findAll('a'):
                    email4 = email3.text
                    print(email4)
它没有打印我期望的电子邮件

它与selenium PhantomJS解析器配合使用,后者需要很长时间才能显示电子邮件地址


请使用正确的解析器立即返回电子邮件地址,以帮助解决此问题。

您的代码很好,但问题是
的内容如下所示:

<span itemprop="email">
<script language="javascript" type="text/javascript">
<!--
{document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,101,110,113,117,105,114,105,101,115,64,97,108,122,104,101,105,109,101,114,115,114,101,115,101,97,114,99,104,117,107,46,111,114,103,34,32,62,101,110,113,117,105,114,105,101,115,64,97,108,122,104,101,105,109,101,114,115,114,101,115,101,97,114,99,104,117,107,46,111,114,103,60,47,97,62))}
//-->
</script>
</span>
输出:

enquiries@alzheimersresearchuk.org

我希望这是一个答案,但不是被用于垃圾邮件!此外,此程序会发出请求,Beautiful Soup必须解析HTML,因此它不是“即时的”。

非常感谢。它就像一个符咒。我得到了我所期望的。。你真棒!请告诉我怎么做。我做到了,谢谢GgorlenHi,过了一段时间,我再次运行代码,没有任何更改。但它会抛出类似“NameError:电子邮件未定义”的错误。请对此提供帮助。谢谢。在您更新了答案之后,它运行良好,代码现在看起来很完美。如果再有麻烦,我会告诉你的。谢谢你的支持
enquiries@alzheimersresearchuk.org