pdf.py 文件源码

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

项目:osp-scraper 作者: opensyllabus 项目源码 文件源码
def extract_links(self, response):
        pdf = pyPdf.PdfFileReader(BytesIO(response.body))
        pgs = pdf.getNumPages()

        for page_num in range(pgs):
            page = pdf.getPage(page_num)

            annotations = page.get('/Annots', [])
            for annotation in annotations:
                annot_object = annotation.getObject()

                a_tag = annot_object.get('/A')
                if a_tag and '/URI' in a_tag:
                    uri = a_tag['/URI']
                    if isinstance(uri, pyPdf.generic.ByteStringObject):
                        uri = uri.decode("utf-8").replace("\x00", "")
                    yield (uri, uri)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号