python爬虫搜索点击_python 爬虫:手动输入验证码点击搜索

2016-05-18 回答

#给你个例子参考 验证码请求一次就变了

#!/usr/bin/python

#coding=utf-8

import requests

import urllib

import urllib2,hashlib,md5

from beautifulsoup import beautifulsoup

import cookielib

def _md5(password):

md5 = hashlib.md5()

md5.update(str.encode(password))

psw = md5.hexdigest()

return psw

url = 'https://passport.liepin.com/captcha/randomcode?2hy270c2ji1'

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()

verifycode =  res_data.headers['set-cookie'].split(';')[0]

verifycode = verifycode.replace('verifycode=','')

filename = res_data.headers['content-disposition'].split(';')[1].strip()

exec(filename)

cookiejar = cookielib.cookiejar()

opener = urllib2.build_opener(urllib2.httpcookieprocessor(cookiejar))

vidcode= raw_input(u"请输入验证码(在本路径 1.jpg): ")

data = {'user_login':"lovesword85@yeah.net",

'ismd5':"1",

'user_pwd':_md5('love123456'),

'verifycode':vidcode,

'url':""}

url = 'https://passport.liepin.com/h/login.json'

data = urllib.urlencode(data)

headers = {'content-type': 'application/x-www-form-urlencoded', 'x-requested-with': 'xmlhttprequest', 'cookie': 'verifycode={0};'.format(verifycode)}

request = urllib2.request(url,data,headers)

response = opener.open(request)

print '-------result-------------'

print response.read()

print '-------headers-------------'

print response.headers

print '-------cookies-------------'

for cookie in cookiejar:

print cookie

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值