pythonはテキストのURLを削除します。
880 ワード
一、テキストのURLを取得する
テキストの内容:
コードの実装:
コードの実装:
テキストの内容:
!http://qiye.tianya.cn//blog/infoReader3.aspx?blogID=1776&ComID=129956&infoID=9724&infoType=1 !
test.txtテキストに置くコードの実装:
import re
f=open('test.txt','r')
s=f.read()
bb=re.findall(r'http://[a-zA-Z0-9.?/&=:]*',s)
f.closed
print bb
結果:['http://qiye.tianya.cn//blog/infoReader3.aspx?blogID=1776&ComID=129956&infoID=9724&infoType=1']
二、テキストの中のurlを取り除く。コードの実装:
# python
import re
f=open('test.txt','r')
s=f.read()
results=re.compile(r'http://[a-zA-Z0-9.?/&=:]*',re.S)
dd=results.sub("",s)
f.closed
d=open('test.txt','w')
d.write(cc)
d.closed
test.txtを再開すると、出現します。 ! !
urlが除去されました