Skip to content

Instantly share code, notes, and snippets.

@iloahz
Created May 17, 2013 04:56

Revisions

  1. iloahz renamed this gist May 17, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. iloahz created this gist May 17, 2013.
    23 changes: 23 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    class V2exHandler(webapp2.RequestHandler):
    def get(self, cmd):
    return
    if cmd == 'daily':
    url = 'http://v2ex.com/signin'
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    opener.addheaders = [('User-Agent', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31'),
    ('Referer', 'http://v2ex.com/signin')]
    res = opener.open(url)
    soup = BeautifulSoup(res)
    soup = soup.findAll('form')[1]
    once = soup.findAll('tr')[2].findAll('td')[1].find('input')['value']
    form = {'u' : 'iloahz', 'p' : 'xxoohowkuaile', 'next' : '/', 'once' : once}
    res = opener.open(url, urllib.urlencode(form))
    url = 'http://v2ex.com/mission/daily'
    res = opener.open(url)
    soup = BeautifulSoup(res)
    soup = soup.findAll('input')
    url = soup[1]['onclick'].split("'")[1]
    url = 'http://v2ex.com' + url.strip()
    res = opener.open(url)
    logging.info('Retrieved Successfully!')