Created
June 3, 2013 16:35
-
-
Save ipconfiger/5699426 to your computer and use it in GitHub Desktop.
用来抽奖用的程序
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import datetime | |
from bs4 import BeautifulSoup | |
import random | |
def get_page(url): | |
r=requests.get(url,headers={"content-type":"text","User-Agent":"Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"}) | |
return BeautifulSoup(r.text) | |
def get_member(): | |
url="http://v2ex.com/t/70983" | |
dom = get_page(url) | |
members = [] | |
for node in dom.find_all("strong"): | |
for sub in node.contents: | |
if u"member" in unicode(sub): | |
members.append(node.get_text()) | |
return members | |
def main(): | |
members = get_member() | |
random.shuffle(members) | |
select_idx = random.randint(0,len(members)-1) | |
print "execued at %s"%datetime.datetime.now() | |
print "the winner is %s"%members[select_idx] | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment