def get(self): content = '' page = Page.query(Page.Path == self.request.path).get() if page == None: page = Page.query(Page.Path == '404').get() if page == None: content = '404 Not Found' else: content = page.Content else: content = page.Content self.write(content)
def parse(html): document = Selector(text=html) memes = [ catch_errors(parse_meme, element) for element in document.css("main .media-element") ] memes = [meme for meme in memes if meme is not None] title = document.css("title::text").get() next_page_url = "/kwejk/page/" + get_last_part_url( document.css(".btn-next::attr(href)").get()) return Page(title, memes, next_page_url)
def parse(html): document = Selector(text=html) memes = [ catch_errors(parse_meme, element) for element in document.css("article.story") ] memes = [meme for meme in memes if meme is not None] title = document.css("title::text").get() next_page_url = "/anonimowe/page/" + find_id_in_url( document.css("nav.pagination > div.next > a::attr(href)").get() ) return Page(title, memes, next_page_url)
def parse(html): document = Selector(text=html) memes = [ catch_errors(parse_meme, element) for element in document.css(".demotivator") ] memes = [meme for meme in memes if meme is not None] title = document.css("title::text").get() next_page_url = "/demotywatory/page/" + get_last_part_url( document.css("a.next-page::attr(href)").get()) return Page(title, memes, next_page_url)
def parse(html): document = Selector(text=html) memes = [ catch_errors(parse_meme, element) for element in document.css("div.pic") ] memes = [meme for meme in memes if meme is not None] title = document.css("title::text").get() next_page_url = "/mistrzowie/page/" + get_last_part_url( document.css(".list_next_page_button::attr(href)").get()) return Page(title, memes, next_page_url)
def parse(raw, nsfw=False): json = loads(raw) posts = json["data"]["posts"] memes = [catch_errors(parse_meme, post) for post in posts] memes = [meme for meme in memes if meme is not None] next_page_url = None result = NEXT_CURSOR.match(json["data"]["nextCursor"]) if result: if nsfw is True: next_page_url = "/9gagnsfw/page/" + result.group(1) else: next_page_url = "/9gag/page/" + result.group(1) return Page(None, memes, next_page_url)