from argparse import ArgumentParser
import os.path
+
+from typing import Iterable
+
from bs4 import BeautifulSoup
from bs4.element import Tag
import requests
assert isinstance(text, Tag)
return text
+ def replies(self) -> Iterable[Tag]:
+ replies = self._html.find_all("div", class_="post-reply")
+ assert all(isinstance(r, Tag) for r in replies)
+ return replies
+
def command_line_parser() -> ArgumentParser:
parser = ArgumentParser(prog='paperdoorknob', description='Print glowfic')
<div class="post-container post-post">
This is glowfic
</div>
+ <div class="flat-post-replies">
+ <div class="post-container post-reply">
+ You sure?
+ </div>
+ <div class="post-container post-reply">
+ Pretty sure.
+ </div>
+ </div>
</body>
</html>'''
self.send_response(self._response_code())
post = paperdoorknob.Post(paperdoorknob.fetch(
f"http://localhost:{self._port()}", s, TIMEOUT))
self.assertEqual(post.text().text.strip(), "This is glowfic")
+ self.assertEqual([r.text.strip() for r in post.replies()],
+ ["You sure?", "Pretty sure."])
def testFetchErrors(self) -> None:
with requests.session() as s: