1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# -*- coding: cp1252 -*-
import nltk
import re
import urllib2
from urllib2 import urlopen
import cookielib
from cookielib import CookieJar
import time
print "khadi"
cj=CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders=[('User-agent','Mozilla/5.0')]
f = open("C:\\Users\\khadi\\Desktop\\corpus\\sport.txt", "rU").read();
tab = f.split("\n")
di = nltk.FreqDist()
#nbr = 0;
tablien = []
for line in tab:
#if line.startswith("http"):
lien = line
print line
sourceCode=opener.open(line).read()
fichier1 = open ("sprt.txt", "w")
texte = re.sub("é","e",sourceCode)
texte = re.sub("é","e",sourceCode)
texte = re.sub("è","e",sourceCode)
texte = re.sub("ê","e",sourceCode)
texte = re.sub("î","i",sourceCode)
texte = re.sub("à","a",sourceCode)
texte = re.sub("â","a",sourceCode)
texte = re.sub("ocirc;","o",sourceCode)
texte = re.sub(" "," ",sourceCode)
texte = re.sub(""","'",sourceCode)
# texte = re.sub("<Script.*?</Script>"," ",sourceCode)
texte = re.sub("<.*?>","",sourceCode)
#texte = re.sub("^function(.*?){|$}","",sourceCode)
fichier1.write(texte)
print texte |
Partager