python文本处理

1.在文本提取URL

这个主要用于爬虫技术:

把爬取的html页面保存为一个字符串,再从字符串中进行提取URL

比如把一个字符串保存在文件中

Now a days you can learn almost anything by just visiting http://www.google.com. But if you are completely new to computers or internet then first you need to leanr those fundamentals. Next
you can visit a good e-learning site like - https://www.codingdict.com to learn further on a variety of subjects.

然后使用findall()函数进行查找和正则表达式有关的实例。
import re

with open("pathurl_example.txt") as file:
        for line in file:
            urls = re.findall('https?://(?:[-w.]|(?:%[da-fA-F]{2}))+', line)
            print(urls)
原文地址:https://www.cnblogs.com/qiujichu/p/10519802.html