1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| import requests from bs4 import BeautifulSoup import re import sys import datetime
uid="11111" pwd="11111"
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" })
res=http.get("http://www.hostloc.com/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://www.hostloc.com/thread-12949-1-1.html" ,"loginfield":"username" ,"username":uid ,"password":pwd ,"questionid":0 ,"answer":"" ,"loginsubmit":"true" } res=http.post("http://www.hostloc.com/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://www.hostloc.com/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://www.hostloc.com/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://www.hostloc.com/'+url) users.extend(re.findall("(space-uid\S+)\"",res.text)) num+=1 print("今日累了,明日再翻!")
|