吴裕雄--天生自然python学习笔记:案例:用正则表达式查找邮件账号

抓取万水书苑“ ht甲://www.w sbookshow.com/ ”网站中的所有 E-mai l 账号。
import requests,re

regex = re.compile('[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+')
url = 'http://www.wsbookshow.com/'
html = requests.get(url)
emails = regex.findall(html.text)
for email in emails:
    print(email)

程序说明
导入 request 包和 re 包。 re 包就是正则表达式 Cregex ),通过
re . compile 方法创建正则表达式对象 regex .
抓取“http :/川ww. wsbookshow.com/ ”网站的源代码 。
在 html.text 中查找所有 E-mail 账号,然后进行显示。

猜你喜欢

转载自www.cnblogs.com/tszr/p/12020759.html
今日推荐