def search(self):
html = requests.post(
'http://animehaven.org/wp-admin/admin-ajax.php',
data={
'action': 'search_ajax',
'keyword': self.media.metadata['name']
}
).text
html = html.replace('\\n', '')
html = html.replace('\\t', '')
html = html.replace('\\', '')
soup = BeautifulSoup(html, 'html.parser')
results = []
for result in soup.find_all('div', {'class': 'sa_post'}):
title_block = result.find('h6')
link = title_block.find('a') # The first one is the good one
title, href = link.get('title'), link.get('href')
self.logger.debug('Found block {} ({})'.format(title, href))
versions_soup = self._get(href)
versions = list(
('Sub' if 'sub' in x.text.lower() else 'Dub', x.get('href'))
for x in versions_soup.find_all('a', {'class': 'ah_button'})
)
for version, url in versions:
self.logger.debug('-> Found version {}'.format(url))
results.append(('{} ({})'.format(title, version), url))
return SearchResult.from_tuples(self.media, results)
评论列表
文章目录