天天看点

使用BeautifulSoup去除URL标签使用BeautifulSoup去除URL标签

使用BeautifulSoup去除URL标签

原始的文本信息如下图:

使用BeautifulSoup去除URL标签使用BeautifulSoup去除URL标签

处理后的文本信息如下图:

使用BeautifulSoup去除URL标签使用BeautifulSoup去除URL标签

处理代码如下,python 3.5

# encoding = utf-8
from bs4 import BeautifulSoup
import time
import string
t1 = time.time()
f = open('undergraduatePOI.txt','rb')
result = ''
for eachLine in f:
    t = eachLine.strip().decode('utf8')
    soup = BeautifulSoup(t)
    string = soup.get_text()
    print(string)
    result +="\n"+str(string)
f = open('Puser2.txt', "w", encoding='utf-8')
f.write(result)
f.close()
print("\n"+">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+"\n"+"打印完毕")
t2 = time.time()
print("去除URL用时:"+str(t2-t1)+"秒")
           

继续阅读