Joke Collection Website - Blessing messages - Python crawler, the question about verification code. Enter the verification code to search.
Python crawler, the question about verification code. Enter the verification code to search.
#! /usr/bin/python?
#coding=utf-8?
Import? ask
Import? urllib?
Import? urllib2,hashlib,md5
From where? BeautifulSoup? Import? Beautiful voice
Import? Kuchlib
def? _md5 (password):
md5? =? hashlib.md5()?
Md5.update(str.encode (password))
psw? =? md5.hexdigest()
Return? The PacificSouthwest.
Website? =? /captcha/randomcode? 2hy270c2ji 1 '
req? =? urllib2。 Request (url)
res_data? =? urllib2.urlopen(req)
res? =? res_data.read()
Output _ file? =? Open ('1.jpg',? WB’)?
output_file.writelines(res)?
output_file.close()
Verification code? =? res_data.headers['Set-Cookie']。 Split (';' )[0]
Verification code? =? verify code . replace(' verify code = ','')
File name? =? RES _ data . headers[' Content-disposition ']。 Split (';' ) [1]. Strip ()
Execute (file name)
Cookeye? =? Kukri cloth. CookieJar()
Opening? =? urllib2.build_opener(urllib2。 HTTPCookieProcessor(cookiejar))
vidcode=? Raw_input(u "Please enter the verification code (in this path? 1.jpg):? ”)?
Data? =? { ' user _ log in ':" love sword 85 @ yeah . net ",
isMd5':" 1 ",
user _ pwd ':_ MD5(' love 123456 '),
Verifycode': video code,
URL“:”}
Website? =? /h/login.json '
Data? =? Urllib.urlencode (data)
Title? =? {'Content Type':? application/x-www-form-urlencoded ',? X-Requested-With ':XMLHttpRequest ',? Cookie ':verify code = { 0 }; “。 Format (verification code)}
Request? =? urllib2。 Request (url, data, title)
Response? =? Opener.open (request)
Print? -Results-'
Print? response.read()
Print? -Title-'
Print? Response. Title
Print? Cookies.
For what? Cookies? Are you online? cookiejar:
Print? Cookies
- Previous article:Which star fans have you met?
- Next article:Where can I open a stock account in Nanguan District of Changchun?
- Related articles
- How to unsubscribe from the daily life assistant business, China Telecom, are not interested.
- How long will it take for the truck gang to be unsealed?
- Is there a simple SMS platform in Beijing?
- Complete sentences praising women
- Girls always don't return your messages, occasionally reply that there is no sound, and they don't return my messages when playing games, so I say I am watching you play.
- Five Essays on Reading Experience of Sophomore Students
- How does your one-plus-one mobile phone back up data?
- Has anyone been violently collected by Didi Loan? How did you do that?
- What is the instruction for checking credit by SMS?
- My mobile phone is Nokia N8 1. Why can't I get the message from 10086? Other messages can be received. Or you can receive it on another mobile phone, which is N8 1.