#-*-Coding:utf-8-*-
"""
Created on Mon Mar 7 10:53:40 2016
@author: Root
"""
Import Urllib2
Import SSL
From selenium import Webdriver
Sel=webdriver. Firefox ()
loginurl = ' Https://18.63.191.89:80/Account/Login '
Sel.get (loginurl)
sel.find_element_by_id (' USERNAME '). Send_keys (' admin ')
sel.find_element_by_id (' Password '). Send_keys (' Admin ')
Inps=sel.find_elements_by_tag_name (' input ')
Inps[4].click ()
cookie = [item["name"] + "=" + item["value"] for item in Sel.get_cookies ()]
cookiestr = '; '. Join (item for item in cookie)
Ssl._create_default_https_context=ssl._create_unverified_context
def geturlimg (url,filename):
headers = {' Cookie ': cookiestr}
req = Urllib2. Request (URL, headers = headers)
Response = Urllib2.urlopen (req)
Text = Response.read ()
If Len (text) >0:
FD = open (filename, ' W ')
Fd.write (text)
Fd.close ()
#url = ' https://18.63.191.89:80/F/Image/?img=1&id=4355 '
#GetUrlImg (URL)
#i =2000
For I in Range (2753,4517):
Url= ' https://18.63.191.89:80/f/image/?img=1&id={0} '. Format (i)
filename = ' id_{:0>4}.jpg '. Format (i)
Print Url,filename
Geturlimg (URL, '/root/id/' +filename)
Python Crawl photo Simulation browser First login account