Parsing “From” addresses from email text

前端 未结 8 2402
春和景丽
春和景丽 2021-02-19 03:56

I\'m trying to extract email addresses from plain text transcripts of emails. I\'ve cobbled together a bit of code to find the addresses themselves, but I don\'t know how to mak

8条回答
  •  没有蜡笔的小新
    2021-02-19 04:46

    if you can be reasonably sure that lines containing these email addresses start with whitespace followed by "From:" you can simply do this:

    addresslines = []
    for line in open("text.txt"):
        if line.strip().startswith("From:"):
            addresslines.append(line)
    

    then later - or on adding them to the list - you can refine the addresslines items to give out exactly what you want

提交回复
热议问题