|
发表于 2018-1-8 13:24:29
|
显示全部楼层
py版本1
- #!/usr/bin/python
- #encoding=utf-8
- import requests
- from bs4 import BeautifulSoup
- import re
- import sys
- import datetime
- uid="username" #用户名
- pwd="userpasswd" #密码
- http = requests.Session()
- http.headers.update({
- 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
- ,'Accept-Language':"zh-CN,zh;q=0.8,ko;q=0.6,zh-TW;q=0.4"
- })
- #http.proxies = {"http":"http://127.0.0.1:8080","https":"http://127.0.0.1:8080"}
- ##打开登陆界面
- res=http.get("http://hostloc.wiki/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login")
- match=re.search(r'name="formhash" value="(\S+)"',res.text)
- if(match):
- formhash=match.group(1)
- else:
- exit(0)
-
- ##登陆
- form={
- "formhash":formhash
- ,"referer":"http://hostloc.wiki/thread-12949-1-1.html"
- ,"loginfield":"username"
- ,"username":uid
- ,"password":pwd
- ,"questionid":0
- ,"answer":""
- ,"loginsubmit":"true"
- }
- res=http.post("http://hostloc.wiki/member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash=LWKbr&inajax=1",data=form)
- match=re.search(r"'uid':'",res.text)
- if(match):
- print("登陆成功")
- else:
- print("登陆失败")
- exit(0)
- ##查询今天访问的空间数量
- res=http.get("http://hostloc.wiki/home.php?mod=spacecp&ac=credit&op=log&suboperation=creditrulelog")
- bs=BeautifulSoup(res.text,"html.parser")
- td=bs.find('td',string="访问别人空间")
- if(td==None):
- print("信息获取失败")
- exit(0)
- tds=td.parent.find_all("td")
- today_view_count=int(tds[2].text) #今天已经翻牌数
- last_view_date=tds[5].text #上次翻牌时间,这个时间不会自动刷新,所以不能仅仅依据数量就决定不翻牌
- need_view=last_view_date.find(datetime.datetime.now().strftime("%Y-%m-%d"))==-1 #上次翻牌时间是不是今天,不是今天则需要翻
- if(today_view_count>=10 and (not need_view)): #不论数量多少,只要上次翻牌时间不是今天就翻。上次翻牌是今天才去判断数量
- print("今日累了,明日再翻!")
- exit(0)
- ##去首页获取等待临幸的网址
- res=http.get("http://hostloc.wiki/forum-45-1.html")
- users =re.findall("(space-uid\S+)"",res.text)
- viewed=set()
- num=0
- while num <13:
- url = users.pop()
- if(url in viewed):continue
- viewed.add(url)
- print(url)
- res=http.get('http://hostloc.wiki/'+url)
- users.extend(re.findall("(space-uid\S+)"",res.text))
- num+=1
-
- print("今日累了,明日再翻!")
复制代码
py版本2
- #-*- coding=utf-8 -*-
- import requests
- import re
- import cookielib
- import sys
- index='http://hostloc.wiki/'
- page_url='http://hostloc.wiki/forum-45-1.html'
- credit_url='http://hostloc.wiki/home.php?mod=spacecp&ac=credit&showcredit=1'
- login_url='http://hostloc.wiki/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1'
- login_data={
- 'fastloginfield':'username'
- ,'username':''
- ,'cookietime':'2592000'
- ,'password':''
- ,'quickforward':'yes'
- ,'handlekey':'ls'
- }
- headers={
- 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
- ,'Accept-Encoding':'gzip, deflate, sdch'
- ,'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6'
- ,'Host':'hostloc.wiki'
- ,'Referer':'http://hostloc.wiki/forum.php'
- ,'Upgrade-Insecure-Requests':'1'
- ,'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
- }
-
-
- class HostLoc():
- def __init__(self,username,passwd):
- self.username=username
- self.passwd=passwd
- login_data['username']=username
- login_data['password']=passwd
- self.session=requests.Session()
- self.session.headers=headers
- self.login()
- self.pass_jdkey()
-
- def pass_jdkey(self):
- html=self.session.get(index).content
- try:
- jdkey=re.findall('jdfwkey=(.*?)"')[0]
- except:
- jdkey=''
- url=index+'?jdfwkey='+jdkey
- self.session.get(index)
-
- def login(self):
- self.session.post(login_url,data=login_data)
-
- def isLogin(self):
- url='http://hostloc.wiki/home.php?mod=spacecp'
- html=self.session.get(url).content
- UserName=re.findall(self.username,html)
- if len(UserName)==0:
- return False
- else:
- return True
- def get_credit(self):
- html=self.session.get(credit_url).content
- credit_pattern=re.compile(r'</ul><ul class="creditl mtm bbda cl"><li class="xi1 cl"><em> 金钱: </em>(.*?) .*? </li>[\w\W]*?<li><em> 威望: </em>(.*?) </li>[\w\W]*?<li class="cl"><em>积分: </em>(.*?) <span class="xg1">')
- try:
- credit=credit_pattern.findall(html)
- coin,wh,jf=credit[0]
- print u"金币:%s,威望:%s,积分:%s"%(coin,wh,jf)
- return True
- except:
- print u"获取数据失败,请稍后再试"
- return False
-
- def get_user(self):
- print('parse '+page_url)
- self.html=self.session.get(page_url).content
- user_pattern=re.compile('space-uid-\d+?.html')
- users=list(set(user_pattern.findall(self.html)))
- self.users=[index+i for i in users]
- def visit_user(self):
- for user in self.users[:10]:
- print('visit user '+user)
- self.session.get(user)
-
- if __name__=='__main__':
- username='' #用户名
- passwd='' #密码
- hostloc=HostLoc(username,passwd)
- if hostloc.get_credit():
- hostloc.get_user()
- hostloc.visit_user()
- hostloc.get_credit()
- else:
- sys.exit(0)
复制代码
py洁癖版(需要自己动手修改部分)
- import requests
- import time
- s = requests.Session()
- s.post("http://hostloc.wiki/member.php", {'username':'XXXX', 'password': 'xxxxxx',})
- urls = ["http://hostloc.wiki/space-uid-{}.html".format(str(i)) for i in range(10000, 24000)]
- for i in urls:
- s.get(i)
- time.sleep(3)
复制代码
php版
- <?php
- function login_post($url, $cookie, $post) {
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
- curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
- curl_exec($curl);
- curl_close($curl);
-
- }
- function get_content($url, $cookie) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
- $rs = curl_exec($ch);
- curl_close($ch);
- return $rs;
- }
- $post = array(
- 'mod' => 'logging',
- 'action' => 'login',
- 'loginsubmit' => 'yes',
- 'infloat' => 'yes',
- 'lssubmit' => 'yes',
- 'username' => '账号',
- 'password' => '密码'
- );
- $url = "http://hostloc.wiki/member.php";
- $cookie = dirname(__FILE__) . '/cookie_lochost.txt';
- login_post($url, $cookie, $post);
- for ($i = 0; $i <= 12; $i++) {
- $url2 = "http://hostloc.wiki/space-uid-" . rand(10000, 24000) . ".html";
- $content = get_content($url2, $cookie);
- echo $content;
- }
- ?>
复制代码
当然 还有exe版 我就不放了 |
|