1. 程式人生 > >python文本處理

python文本處理

使用 with open most 字符串 als lin can fir Coding

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文本處理