| 16137 |
kshitij.so |
1 |
from selenium import webdriver
|
|
|
2 |
from selenium.webdriver.common.keys import Keys
|
|
|
3 |
import time
|
|
|
4 |
#from dtr.utils.utils import get_mongo_connection
|
|
|
5 |
import urllib2
|
|
|
6 |
import datetime
|
|
|
7 |
|
|
|
8 |
USER_NAME = "1202479977"
|
|
|
9 |
PASSWORD = "5409"
|
|
|
10 |
#VOI_USER_NAME = "spiceonlineretailvoi@gmail.com"
|
|
|
11 |
#VOI_PASSWORD = "saholicsnapdeal1"
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
headers = {
|
|
|
15 |
"Accept":"*/*",
|
|
|
16 |
"Accept-Encoding":"gzip,deflate",
|
|
|
17 |
"Accept-Language":"en-US,en;q=0.8",
|
|
|
18 |
"Connection":"keep-alive",
|
|
|
19 |
"Host":"dial2verify.com",
|
|
|
20 |
"Origin":"https://dial2verify.com",
|
|
|
21 |
"Referer":"https://dial2verify.com/corp/control-panel/v2/Dial2Verify_UI_Data_export.php",
|
|
|
22 |
"User-Agent":"Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36",
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
def run():
|
| 16239 |
kshitij.so |
28 |
try:
|
|
|
29 |
driver = webdriver.PhantomJS('/usr/local/bin/phantomjs')
|
|
|
30 |
driver.set_window_size(1124, 850) # set browser size.
|
|
|
31 |
driver.get("https://dial2verify.com/corp/control-panel/v2/login.php")
|
|
|
32 |
driver.maximize_window()
|
|
|
33 |
element = driver.find_element_by_name("username")
|
|
|
34 |
element.send_keys(USER_NAME)
|
|
|
35 |
element = driver.find_element_by_name("password")
|
|
|
36 |
element.send_keys(PASSWORD)
|
| 16137 |
kshitij.so |
37 |
|
| 16239 |
kshitij.so |
38 |
element = driver.find_element_by_css_selector(".runner-button")
|
|
|
39 |
element.click()
|
|
|
40 |
time.sleep(5)
|
|
|
41 |
driver.get("https://dial2verify.com/corp/control-panel/v2/Dial2Verify_UI_Data_export.php")
|
|
|
42 |
time.sleep(5)
|
|
|
43 |
element = driver.find_element_by_css_selector(".runner-button")
|
|
|
44 |
element.click()
|
|
|
45 |
cookieMap = {}
|
|
|
46 |
cookie = ""
|
|
|
47 |
for x in driver.get_cookies():
|
|
|
48 |
if x.get('name') == "lhc_per":
|
|
|
49 |
cookieMap['lhc_per'] = x.get('value')
|
|
|
50 |
elif x.get('name') == "PHPSESSID":
|
|
|
51 |
cookieMap['PHPSESSID'] = x.get('value')
|
|
|
52 |
else:
|
|
|
53 |
pass
|
| 18688 |
manas |
54 |
#cookie = "lhc_per="+cookieMap['lhc_per']+";PHPSESSID="+cookieMap['PHPSESSID']
|
|
|
55 |
cookie = "PHPSESSID="+cookieMap['PHPSESSID']
|
| 16239 |
kshitij.so |
56 |
return cookie
|
|
|
57 |
finally:
|
|
|
58 |
print "Closing driver "
|
|
|
59 |
driver.quit()
|
|
|
60 |
|
| 16137 |
kshitij.so |
61 |
|
|
|
62 |
def downloadFile(cookie):
|
|
|
63 |
headers['cookie'] = cookie
|
|
|
64 |
url = "https://dial2verify.com/corp/control-panel/v2/Dial2Verify_UI_Data_export.php?type=excel2007&records=all&rndVal=0.1899"
|
|
|
65 |
req = urllib2.Request(url,headers=headers)
|
|
|
66 |
res = urllib2.urlopen(req)
|
| 16139 |
kshitij.so |
67 |
filePath = "/tmp/dial2verify"+str(datetime.datetime.now())+".xlsx"
|
| 16137 |
kshitij.so |
68 |
output = open(filePath,'wb')
|
|
|
69 |
output.write(res.read())
|
|
|
70 |
output.close()
|
|
|
71 |
return filePath
|
|
|
72 |
|
|
|
73 |
def main():
|
|
|
74 |
cookie = run()
|
|
|
75 |
return downloadFile(cookie)
|
|
|
76 |
|
|
|
77 |
if __name__ == '__main__':
|
|
|
78 |
main()
|
|
|
79 |
|