加载中…
个人资料
fffonion
fffonion
  • 博客等级:
  • 博客积分:0
  • 博客访问:459
  • 关注人气:3
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

绅士网(exhentai.org)抓站小记录

(2013-03-21 22:42:27)
标签:

杂谈

绅士网是一个著名的18x漫画网站。

其主站g.e-hentai.org默认对象为全年龄向,因此打开不和谐内容时会蹦出小框框。
而exhentai.org是18x向的,不会跳框框,也有更多的资源。
oschina上有人写了用urllib2抓站的python脚本,不怎么好用,决定用httplib2重写一个。
而exhentai.org是木有登陆页面的,也就是无法从exhentai.org上直接登录绅士(里)

于是用http analyzer抓了一下包(点击看大图):
http://ww3/large/436919cbjw1e2xqmumeufj.jpg
然后第二个请求的详细信息为:
http://ww4/large/436919cbjw1e2xqtgt8w4j.jpg
因此是这么个流程:

  1. 当访问exhentai时检查有无cookie,没有则302到http://forums.e-hentai.org/remoteapi.php?ex=xxx1,这个页面可以获取e-hentai上已登录的用户的cookie,计算一个xxx2值
  2. 然后上面这个页面返回302到http://exhentai.org/?poni=xxx2
  3. 上面这个返回set-cookie头

其中,xxx1和xxx2都是base64编码过的字符串;
xxx1解码后结果类似为“1363873263-f5bc9e17b0”,大概是时间和它的md5 with salt
xxx2解码后结果类似为'1043216-c036cef9fe30e7f918d0b058c7bcf3e8-1363873264-fca98963a9849f0d96f59e1fc702a6887ff31a28',大概是 用户id-密码md5 with salt-时间-前面这些的md5 with salt

嘛,反正直接GET最后那个页面这种途径是搞不定了;而且一开始还在想,yay又是个什么东西……

其实……解决办法是很简单的。

浏览器中的cookie是有域限制的,(也因此exhentai才要这么麻烦地来回302)。

然后哥就试了下直接把e-hentai的cookie用到exhentai上会怎么样

loginurl='http://e-hentai.org/bounce_login.php?b=d&bt=1-1 HTTP/1.1'
baseurl='http://g.e-hentai.org/g/484928/779f13d079/'
exurl='http://exhentai.org/g/577197/cb3ec224f5/'

logindata={
    'ipb_login_password':'******',
    'ipb_login_submit':'Login!',
    'ipb_login_username':'*******'}
req = urllib2.Request(loginurl)
resp=urllib2.urlopen(req,urllib.urlencode(logindata))#POST登陆
coo=resp.info().getheader('Set-Cookie')#获得cookie串
cooid=re.findall('ipb_member_id=(.*?);',coo)[0]
coopw=re.findall('ipb_pass_hash=(.*?);',coo)[0]
print cooid,coopw
headers = {'Cookie': 'ipb_member_id='+cooid+';ipb_pass_hash='+coopw\
           ,'User-Agent':"User-Agent':'Mozilla/5.2 (compatible; MSIE 8.0; Windows NT 6.2;)"}
resp, content = httplib2.Http().request(exurl, 'GET', headers=headers)
print len(content)
print re.findall('.+son',content)

然后我非常神奇地看到了下面的输出

1043221 c036cef9fe91e7f918d0b058c7bcf3e8
15850
['<title>[Crimson',……

擦……竟然正常返回了……看来yay是果然用来坑爹的……

看来不用CookieJar是有好处的=。=cookie这种东西果然还是自己动手丰衣足食啊

嗯这样一来所有难点都解决了,嗯~

查看原文:http://www.yooooo.us/2013/crawl-exhentai

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有