Analog Login Code
deflogin (): fromSeleniumImportVebdriver Browser= Webdriver. Chrome (executable_path='E:/test/chromedriver.exe')#inside the parentheses is the path of the environment, the window is configured so that it is not possible to use this path .Browser.get ('Http://www.zhihu.com.signin')##访问的页面, which is the page that needs to be landedBrowser.find_element_by_css_selector ('. Sigflow.input'). Send_keys ('Account Number')##输入的帐号和密码, you write more. #one thing to note here is that you try to put your time in a little bit longer when you type it, and the best thing to do is to divide it into several times.Browser.find_element_by_css_selector ('. Button.input'). Click ()##点击的那个按钮 ImportTime Time.sleep (10) #Get CookiesCookies =browser.get_cookies ()Print(Cookies) cookie_dict= {} ImportPickle forCookiesinchCookies:#Write Filef = open ('g:/scrapy/'+cookie['name']+'. Lagou','WB') Pickle.dump (cookie,f) f.close ()#The above is a cookie written to the filecookie_dict[cookie['name']] = cookie['value'] #This is present on the disk.Browser.close ()#Close Browser return[Scrapy. Request (url=self.start_urls[0],dont_filter=true,cookies =cookie_dict)] #return a cookie to which URL #Be sure to take care to open the cookie inside the setting.
Analog Login Get Cookie