Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Tornado and PyQuery for parsing myshows.ru links for user profiles
# -*- coding: utf-8 -*-
from tornado import ioloop
from tornado import web
from tornado import httpclient
from tornado.escape import (json, json_decode, json_encode)
from pyquery import PyQuery
class ParseUsersHandler(web.RequestHandler):
def get(self):
client = httpclient.HTTPClient()
try:
response = client.fetch("http://myshows.ru/search/users/")
jQuery = PyQuery(response.body)
links = []
jQuery("ul.users.users-quad > li > a").each(lambda i, el: links.append(PyQuery(el).attr("href")))
self.write(json_encode(links))
except httpclient.HTTPError, e:
print "Error:", e
application = web.Application(
[
(r"/rest/parser/users", ParseUsersHandler)
],
cookie_secret="QQ#j(leMvennf^&$(J000KIKh23373b#FFF$e",
debug=True
)
if __name__ == '__main__':
import logging
logging.getLogger().setLevel(logging.DEBUG)
application.listen(6848)
ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.