首页 > 编程语言 > 详细

python文本处理

时间:2019-03-12 21:40:44      阅读:141      评论:0      收藏:0      [点我收藏+]

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("path\url_example.txt") as file:
        for line in file:
            urls = re.findall(https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+, line)
            print(urls)

 

python文本处理

原文:https://www.cnblogs.com/qiujichu/p/10519802.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!