python从Excel中提取邮箱

从各个城市的律师协会去爬取的律师的招聘信息,可是邮箱在招聘简介里面,所有需要写个脚本去提取邮箱

import pandas as pd
import re

regex = r"([-_a-zA-Z0-9\.]{0,64}@([-\w]{1,63}\.)*[-a-zA-Z0-9-.]{1,63})"

regex_1 = r"([a-zA-Z0-9_.+-]+@[a-pr-zA-PRZ0-9-]+\.[a-zA-Z0-9-.]+)"
df = pd.read_excel('11-28+深圳律师.xls')
# for d in df['福利待遇及联系信息(必填)']:
#     emails = re.findall(regex, d)
#     if emails:
#         print(emails[0])
#     else:
#         print('wu')

for i in range(len(df['福利待遇及联系信息(必填)'])):

    email = re.findall(regex, df['福利待遇及联系信息(必填)'][i])
    email_1 = re.findall(regex_1, df['福利待遇及联系信息(必填)'][i])
    print(email,email_1)
    if email_1:
        df['HR邮箱(必填)'][i] = email_1[0]
    elif email:

        df['HR邮箱(必填)'][i] = email[0][0]
    else:
        print(i)

        break


df.to_excel('shenzhen.xls')

  

posted @ 2018-11-28 14:13  zhong_sp  阅读(603)  评论(0编辑  收藏  举报