-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiphin5.py
217 lines (195 loc) · 5.57 KB
/
iphin5.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import nltk
import requests
import urllib.request
from urllib.parse import urlparse
import bs4
import pandas as pd
import re
import operator
import gc
from nltk.tokenize import sent_tokenize, word_tokenize
from bs4 import BeautifulSoup
from pandas import read_csv
from urllib.parse import urlparse
import csv
lang_data = pd.read_csv(r"url_data.txt",usecols=[0],sep='\\t',engine='python')
url_data = pd.read_csv(r"url_data.txt",usecols=[1],sep='\\t',engine='python')
lang_word = []
for index, row in lang_data.iterrows():
lang_word.append(row['language'])
url_site = []
for index, row in url_data.iterrows():
url_site.append(row['site'])
ph_word0 = []
ph_word1 = []
ph_word2 = []
ph_word3 = []
ph_word4 = []
ph_word5 = []
ph_word6 = []
ph_word7 = []
ph_word8 = []
ph_word9 = []
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[0],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word0.append(row['english'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[1],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word1.append(row['urdu'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[2],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word2.append(row['punjabi'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[3],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word3.append(row['marathi'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[4],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word4.append(row['malayalam'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[5],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word5.append(row['kannada'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[6],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word6.append(row['hindi'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[7],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word7.append(row['gujarati'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[8],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word8.append(row['bengali'])
ph_data = pd.read_csv(r"ph_ftrs51dic.csv",usecols=[9],sep=',',engine='python')
for index, row in ph_data.iterrows():
ph_word9.append(row['telugu'])
def lang_id(counter):
for s in lang_word:
word = lang_word[counter]
return word
def lang_url(counter):
for s in lang_word:
t = url_site[counter]
return t
buf_word = ' frequency= '
def ftch_ece(url_string):
r = requests.get(url_string)
type(r)
html = r.text
soup = BeautifulSoup(html, "html5lib")
type(soup)
text = soup.get_text()
words = re.findall('\w+', text)
sw = nltk.corpus.stopwords.words('english')
words_ns = []
for word in words:
if word not in sw:
words_ns.append(word.lower())
word_freq = []
for w in ph_word0:
n = operator.countOf(words_ns, w)
if n > 0:
word_freq.append([w])
word_freq.append([n])
return url,buf_word,word_freq
def ftch_cms(url_string):
r = requests.get(url_string)
type(r)
html = r.text
soup = BeautifulSoup(html, "html5lib")
type(soup)
text = soup.get_text()
words = re.findall('\w+', text)
sw = nltk.corpus.stopwords.words('english')
words_ns = []
for word in words:
if word not in sw:
words_ns.append(word.lower())
word_freq = []
for w in ph_word0:
n = operator.countOf(words_ns, w)
if n > 0:
word_freq.append([w])
word_freq.append([n])
return url_string,buf_word,word_freq
def ftch_asp(url_string):
r = requests.get(url_string)
type(r)
html = r.text
soup = BeautifulSoup(html, "html5lib")
type(soup)
text = soup.get_text()
words = word_tokenize(text)
word_freq = []
count = 0
for s in ph_word9:
t = ph_word0[count]
count += 1
n = operator.countOf(words, s)
if n > 0:
word_freq.append([t])
word_freq.append([n])
return url_string,buf_word,word_freq
count = 0
for s in lang_word:
t = url_site[count]
count = count + 1
if s == 'english':
html = requests.get(t)
soup = bs4.BeautifulSoup(html.text,"lxml")
for link in soup.select("a[href$='.ece']"):
url = link.get('href')
print(ftch_ece(url))
for link in soup.select("a[href$='.cms']"):
url = link.get('href')
result = urlparse(url)
if all([result.scheme, result.netloc]):
url3 = url
print(ftch_cms(url))
else:
url = url3 + url
print(ftch_cms(url))
elif s == 'telugu':
source = urllib.request.urlopen(t).read()
soup = bs4.BeautifulSoup(source,'lxml')
for link in soup.select("a[href$='.aspx']"):
url2 = link.get('href')
result = urlparse(url2)
if all([result.scheme, result.netloc]):
url3 = url2
print(ftch_asp(url2))
else:
url2 = url3 + url2
print(ftch_asp(url2))
elif s == 'urdu':
source = urllib.request.urlopen(t).read()
soup = bs4.BeautifulSoup(source,'lxml')
for link in soup.select("a[href$='.html']"):
url2 = link.get('href')
result = urlparse(url2)
if all([result.scheme, result.netloc]):
url3 = url2
print(ftch_asp(url2))
else:
url2 = url3 + url2
print(ftch_asp(url2))
elif s == 'bengali':
html = requests.get(t)
soup = bs4.BeautifulSoup(html.text,"lxml")
links = soup.find_all('a')
for link in links:
try:
url2 = link['href']
result = urlparse(url2)
if all([result.scheme, result.netloc]):
text = soup.get_text()
words = word_tokenize(text)
word_freq = []
count=0;
for s in ph_word8:
e = ph_word0[count]
count = count +1
n = operator.countOf(words, s)
if n > 0:
word_freq.append([e])
word_freq.append([n])
print(url2,buf_word,word_freq)
except:
pass