Created
May 7, 2013 15:06
-
-
Save gin0606/5533337 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
#!/usr/local/bin/python | |
# -*- coding: utf-8; -*- | |
import datetime | |
import mechanize | |
from pyquery import PyQuery as pq | |
import PyRSS2Gen | |
login_id = '' | |
password = '' | |
class Pixiv(object): | |
def __init__(self, id_='', password=''): | |
self.br = mechanize.Browser() | |
self.br.set_handle_robots(False) | |
self.br.addheaders = [( | |
'User-agent', | |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0.1) Gecko/20100101 Firefox/8.0.1' | |
)] | |
self.url = 'http://www.pixiv.net' | |
self.target = '/bookmark_new_illust.php' | |
self._id = id_ | |
self._password = password | |
def login(self): | |
self.br.open('http://pixiv.net/login.php') | |
try: | |
self.br.select_form(nr = 0) | |
self.br['pixiv_id'] = self._id | |
self.br['pass'] = self._password | |
self.br.submit() | |
except e: | |
print 'login failed' + e | |
def get_html(self): | |
return self.br.open(self.url + self.target) | |
def main(): | |
p = Pixiv(id_ = login_id, password = password) | |
p.login() | |
rss_items = [] | |
d = pq(p.get_html().read().decode('utf-8')) | |
for i in d('ul.images.autopagerize_page_element li.image'): | |
illust_data = pq(i) | |
image_data = pq(illust_data('a')[0]) | |
user_data = pq(illust_data('a')[1]) | |
item = PyRSS2Gen.RSSItem( | |
title = "%s - %s" % (pq(pq(i).children()[0]).text(), | |
pq(i).text()), | |
link = pq(pq(i).children()[0]).attr.href, | |
description = '<a href="%s"><img src="%s" alt="%s" /></a>' % ( | |
image_data.attr.href, | |
pq((pq(pq(i).children()[0]).children()[0])).children().attr.src, | |
pq(pq(i).children()[0]).text(), | |
), | |
guid = PyRSS2Gen.Guid(image_data.attr.href), | |
pubDate = datetime.datetime.now(),) | |
rss_items.append(item) | |
rss = PyRSS2Gen.RSS2( | |
title = "お気に入りユーザー新着イラスト", | |
link = "http://www.pixiv.net/bookmark_new_illust.php", | |
description = "お気に入りユーザー新着イラスト", | |
lastBuildDate = datetime.datetime.now(), | |
items = rss_items) | |
rss.write_xml(open("/Users/kuramitsu/Dropbox/Public/pixiv_bookmark_new_illust.xml", "w+"), "utf-8") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment