1 #!/use/bin/env python2 #-*-coding:utf-8-*3 #Author:nick4 #Desc:v2ex Daily Sign -in5 6 ImportUrllib7 ImportUrllib28 ImportCookielib9 ImportReTen ImportSYS One fromBs4ImportBeautifulSoup as BS A fromDatetimeImportdatetime - - the Reload (SYS) -Sys.setdefaultencoding ('Utf-8') - - + - +Login_url ='Http://www.v2ex.com/signin' #Login Address ADaily_url ='http://www.v2ex.com/mission/daily' #sign -in address atBalance_url ='http://v2ex.com/balance' #account Balance -user ='Test' #Account Number -passwd ='Test' -Today =Datetime.today () -Time = Today.strftime ("%y-%m-%d%x") - in " " - You need to use cookies for session tracking because you need to access the page after login to " " + -Cookie = Cookielib. Cookiejar ()#get a Cookie object theHandler = Urllib2. Httpcookieprocessor (Cookie)#Use the Httpcookieprocessor object of the URLLIB2 library to create a cookie processor *Opener = Urllib2.build_opener (handler)#load cookies, build opener through handler $ Panax Notoginseng " " - Opener: When you get a URL you use a opener (a urllib2. Openerdirector instances). The default opener used in peacetime is Urlopen, a special opener, the can be understood as a special example of opener, the incoming parameters are just url,data,timeout. + " " A the + defget_value (html,name,tag): - " " $ gets the value of the once, which is different every time $ " " -Soup = BS (HTML,'Html.parser') - ifName: theValue = Soup.find (attrs={tag:name}) - Else:WuyiValue =soup.find (TAG) the returnvalue - Wu - deflogin (): About " " $ Login - " " -Login_req =Urllib2. Request (Login_url) -HTML =Opener.open (login_req). Read () AOnce_value = get_value (HTML,'once','name')['value'] + theHeader ={ - 'user-agent':'mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/40.0.2214.94 safari/537.36', $ "Host":"www.v2ex.com", the "Origin":"http://www.v2ex.com", the 'Referer':'Http://www.v2ex.com/signin' the } the -Post_info = {'u': User,'P':p ASSWD,'once': Once_value,'Next':'/'} inPostData =Urllib.urlencode (post_info) thereq =Urllib2. Request (Login_url,postdata,header) theResponse = Opener.open (req,timeout=10) About #print Response.getcode () the #print response.read () the the if not 'A2' inch[C.name forCinchCookie]: + RaiseValueError,"Login failed!" - the Bayi defdaily (): the " " the Daily Login Rewards - " " -Daily_req =Urllib2. Request (Daily_url) theDaily_page =Opener.open (daily_req). Read () theDay = Re.findall (r"have you logged in continuously \s? (\d+) \s? Days", Daily_page) [0] theinfo = get_value (daily_page,'FA fa-ok-sign','class') the ifInfo: - Print "%s Daily Login bonus has been received and has been logged on for%s days consecutively"%(Time,day) the Else: the Print "%s start signing in to collect rewards ....."% Time theonclick = Get_value (Daily_page,'Super Normal button','class')['onclick']94href = Onclick[onclick.find ("'") +1:len (onclick)-2] theFull_url ='http://www.v2ex.com'+href theFull_req =Urllib2. Request (Full_url) thepage =Opener.open (full_req). Read ()98Success = Get_value (Daily_page,'icon-ok-sign','class') About ifSuccess: -Day =Int (day)101Day +=1102 Print "%s Sign in successfully! A daily bonus has been successfully received and has been logged in for%d consecutive days"%(Time,day)103 sys.exit (0)104 Else: the Print "%s Sign in failed! "% Time106 107 defbalance ():108 " "109 account Balance the 111 " " theBalance_req =Urllib2. Request (Balance_url)113Balance_page =Opener.open (balance_req). Read () theSoup = BS (HTML,'Html.parser') the the 117 118 119 - if __name__=='__main__':121 Login ()122Daily ()
View Code
Then throw it to the server because V2EX is reset at 8 check-in time every morning, so set the crontab to 8:10. Then just wait to collect the gold. O (∩_∩) o~~
8 * * * sudo python/mnt/v2ex.py >>/mnt/v2ex.log
Sign in to collect coins script