Created
April 9, 2012 04:53
-
-
Save ryanmcgrath/2341517 to your computer and use it in GitHub Desktop.
Because Quora doesn't have a damn API.
This file contains 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
# -*- coding: utf-8 -*- | |
#!/usr/bin/env python | |
import urllib2 # Quora no like requests requests. ;_; | |
from pyquery import PyQuery as pq | |
from pprint import pprint | |
class Puora(object): | |
def __init__(self, username): | |
self.answers_url = 'http://www.quora.com/%s/answers' % username | |
def get_answers(self): | |
request = urllib2.urlopen(self.answers_url).read() | |
document = pq(request) | |
questions_node = document.find('.main').eq(1).find('.main_col').eq(1).find('.question_link') | |
answers_node = document.find('.main').eq(1).find('.main_col').eq(1).find('.feed_item_answer_content').remove('.feed_item_answer_user').remove('.answer_voters') | |
questions = [question for question in questions_node.map(lambda i, node: pq(node).text())] | |
answers = [answer for answer in answers_node.map(lambda i, node: pq(node).text())] | |
return {'questions': questions, 'answers': answers} | |
p = Puora('Ryan-McGrath') | |
print p.get_answers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It returns nothing, for some reason.
200
HTTP response, but no body or anything. Would presume possibly headers related or some such crap.