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

วิธีใช้ Python Regex ดึง URL จาก HTML Link

ใช้ Python regex ดึง URL จาก HTML link

ตัวอย่าง

import re
s = '''https://www.santa.com'''
match = re.search(r'href=[\'"]?([^\'" >]+)', s)
if match:
    print(match.group(0))

ผลลัพธ์

href="https://www.santa.com"