Skip to content

Commit

Permalink
验证码解决
Browse files Browse the repository at this point in the history
  • Loading branch information
atupal committed Jun 14, 2013
1 parent 134dbd7 commit 0e95ed9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
47 changes: 43 additions & 4 deletions dianzan/dianzan_py-dom-xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,49 @@ def _login(self):
#headers['User-Agent'] = 'curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18'
headers['User-Agent'] = ''

url = self.session.post(url, data = data, headers = headers, allow_redirects = False).headers['location']
#post之后重定向的地址,这里如果允许自动跳转的话不知道为什么会跳转到腾讯首页去。。蛋疼

res = self.session.post(url, data = data, headers = headers, allow_redirects = False)
url = res.headers['location']#post之后重定向的地址,这里如果允许自动跳转的话不知道为什么会跳转到腾讯首页去。。蛋疼

if not url:
raise Exception
data = dict()
img_url = self._parse(None, '//img/@src', content = res.content)[0].content
names = [
'qq' ,
'u_token' ,
'r' ,
'extend' ,
'r_sid' ,
'aid' ,
'hiddenPwd' ,
'login_url' ,
'go_url' ,
'verify' ,
'sidtype' ,
]
for name in names:
value = self._parse(None, '//*[@name="'+ name +'"]/@value', content = res.content)[0].content
data[name] = value
from PIL import Image
from StringIO import StringIO
r = self.session.get(img_url)
verify_img = Image.open(StringIO(r.content))
verify_img.show()
import os
if os.environ['HOME'] == '/home/atupal':
data['verify'] = raw_input("verify:")
url = self._parse(None, '//*/@href', content = res.content)[1].content #post地址
res = self.session.post(url, data = data, headers = headers, allow_redirects = False)
url = res.headers['location']

#验证码后第一次get
url = self._parse(url, '/wml/card/@ontimer')[0].content

#验证码后第二次get
url = self._parse(url, '/wml/card/@ontimer')[0].content
else:
url = self._parse(url, '/wml/card/@ontimer')[0].content #再get一次就登陆成功了 ,以上和chrome浏览器都略有不用,没有302

url = self._parse(url, '/wml/card/@ontimer')[0].content #再get一次就登陆成功了 ,以上和chrome浏览器都略有不用,没有302
self.url = url

#print self.session.get(url).content
Expand All @@ -81,6 +117,9 @@ def dianzan(self, cnt = 5, op = '1'):
#urls = re.findall(patter, content)

feed_url = self.url
url = self._parse(feed_url, '/wml/card/@ontimer') #不知道为什么换了一个qq号的时候这里会多加一个跳转
if url:
feed_url = url[0].content
for i in xrange(cnt):
print feed_url
content = self.session.get(feed_url).content
Expand Down
3 changes: 3 additions & 0 deletions dianzan/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def dianzan(self, cnt = 5, op = '1'):
#urls = re.findall(patter, content)

feed_url = self.url
url = self._parse(feed_url, '/wml/card/@ontimer')
if url:
feed_url = url[0].content
for i in xrange(cnt):
print feed_url
content = self.session.get(feed_url).content
Expand Down

0 comments on commit 0e95ed9

Please sign in to comment.