-
Notifications
You must be signed in to change notification settings - Fork 3
/
requestData.py
38 lines (34 loc) · 951 Bytes
/
requestData.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
import requests
import json
from bs4 import BeautifulSoup
import re
import time
#Script to query the trained model (demo) of (Deri and Knight, 2015)
inFile=open("Data/dataset.csv")
outFile=open("Data/dataAliyaScraped.csv","w")
lineIndex=0
for line in inFile:
words=re.split("\W+",line)
parent1=words[1]
parent2=words[2]
print lineIndex
print parent1
print parent2
parentString="24:"+parent1+":"+parent2
#print parentString
s="http://leps.isi.edu/fst/ajaxGenAll.php"
data = json.dumps( {0: parentString } )
response = requests.post( s, data )
responseText=response.text
index1=responseText.index(":</p>")
index2=responseText.index("<p>Try")
#print index1
#print index2
answer=responseText[index1+11:index2-13]
print answer
outFile.write(parent1+" "+parent2+" "+answer+"\n")
time.sleep(1)
lineIndex+=1
if lineIndex%100==0:
time.sleep(6)
outFile.close()