def parse_book(self, book_id): self.fetch() uid = '{}-{}'.format(self.NAME, book_id) el = self.dom.find('h1') title = el.get_text() title = title.replace(u'最新章节', '') book = Book(uid, title, lang='zh') el = self.dom.find('meta', attrs={'name': 'author'}) author = el.get('content') book.author = author book.chapters = list(self._parse_book_chapters()) return book
def parse_book(self, book_id): self.fetch() uid = '{}-{}'.format(self.NAME, book_id) el = self.dom.find('h1') title = el.get_text() book = Book(uid, title, lang='zh') els = self.dom.select('div#smallcons > span > a') if els: author = els[0].get_text() book.author = author book.chapters = list(self._parse_book_chapters()) return book
def parse_book(self, book_id): self.fetch() uid = '{}-{}'.format(self.NAME, book_id) el = self.dom.find('h1') title = el.get_text() book = Book(uid, title, lang='zh') els = self.dom.select('div#smallcons a') if els: el = els[0] author = el.get_text() book.author = author for item in self._parse_book_chapters(): if isinstance(item, Section): book.add_section(item) else: book.chapters.append(item) return book
def parse_dajia_author(author_id): headers = {'User-Agent': USER_AGENT, 'Referer': REFERRER} t = int(time.time()) params = {'action': 'wz', 'authorid': author_id, '_': t} resp = requests.get(WZ_URL, headers=headers, params=params) if resp.status_code != 200: return None data = resp.json() entries = data.get('data') if not entries: return None latest = entries[0] author = latest.get('name') uid = 'dajia-a-{}'.format(author_id) book = Book(uid=uid, title=author, lang='zh', author=author) book.chapters = [format_item(item) for item in entries] return book
def parse_book(self, book_id): self.fetch() uid = '{}-{}'.format(self.NAME, book_id) els = self.dom.select('h1 > strong') if not els: els = self.dom.select('h2 > b') if els: title = els[0].get_text() else: title = 'Unknown' book = Book(uid, title, lang='zh') for el in self.dom.select('td'): text = el.get_text() m = META_PATTERN.findall(text) if m: group = m[0] book.author = group[0].strip() book.pubdate = group[1].strip() for item in self._parse_book_chapters(): if isinstance(item, Section): book.add_section(item) else: book.chapters.append(item) return book
def parse_dajia_channel(channel_id): headers = {'User-Agent': USER_AGENT, 'Referer': REFERRER} t = int(time.time()) params = {'action': 'wz', 'channelid': channel_id, '_': t} resp = requests.get(WZ_URL, headers=headers, params=params) if resp.status_code != 200: return None data = resp.json() entries = data.get('data') if not entries: return None params = {'action': 'lanmu', 'channelid': channel_id, '_': t} resp = requests.get(CHANNEL_URL, headers=headers, params=params) data = resp.json() title = data['data']['channel']['n_cname'] uid = 'dajia-c-{}'.format(channel_id) book = Book(uid=uid, title=title, lang='zh') book.chapters = [format_item(item) for item in entries] return book