Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

โปรแกรม Python ดึง email-id จากไฟล์ข้อความ URL


ที่นี่เราใช้แพ็คเกจนิพจน์ทั่วไปเพื่อแยก email-id จากไฟล์ URL-text รับไฟล์ข้อความ URL การใช้แพ็คเกจนิพจน์ทั่วไป เรากำหนดรูปแบบของ email-id จากนั้นใช้ฟังก์ชัน findall() โดยใช้วิธีนี้เพื่อตรวจสอบข้อความที่จะจับคู่กับรูปแบบนี้

Input
text= Please contact us at contact@tutorialspoint.com for further information."+\  " You can also give feedback at feedback@tutorialspoint.com"
Output ['contact@tutorialspoint.com ','feedback@tutorialspoint.com']

โค้ดตัวอย่าง

import re
my_text = "Please contact us at contact@tutorialspoint.com for further information."+\
   " You can also give feedback at feedback@tutorialspoint.com"
my_emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", my_text)
print (my_emails)

ผลลัพธ์

['contact@tutorialspoint.com', 'feedback@tutorialspoint.com’]