dl_shakespeare.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Fakespeare 作者: RuthAngus 项目源码 文件源码
def dl_scripts():
    url = BASE_URL
    r = requests.get(url)
    tree = BeautifulSoup(r.text, "html.parser")
    os.makedirs("plays", exist_ok=True)
    for a in tree.find_all("a")[2:-7]:
        link = a.get("href").split("/")[0]
        title = a.text.strip().replace(" ", "_")
        title = title.replace("\n", "_")
        fn = "plays/" + title + ".txt"

        r = requests.get(BASE_URL + "/" + link + "/full.html")
        body = html2text(r.text.replace("blockquote", "p"))
        body = body[body.index("### ACT I"):]
        with open(fn, "w") as f:
            f.write(body)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号