【发布时间】:2017-05-09 08:02:15
【问题描述】:
我正在玩 BeautifulSoup 库。我试图解析来自该网站的电子邮件,但得到了意想不到的结果。这是我的代码:
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup
import re
from urllib.parse import quote
startUrl = "http://getrocketbook.com/pages/returns"
try:
html = urlopen(quote((startUrl).encode('utf8'), ':/?%#_'))
bsObj = BeautifulSoup(html, "html.parser")
alls = bsObj.body.findAll(text=re.compile('[A-Za-z0-9\._+-]+@[A-Za-z0-9\.-]+'))
for al in alls:
print(al)
except HTTPError:
pass
except URLError:
pass
我希望只解析一封电子邮件,但实际上我解析了这个句子:
If you’ve done all of this and you still have not received your refund yet, please contact us at hello@getrocketbook.com.
知道我做错了什么吗?
【问题讨论】:
标签: python regex beautifulsoup