在pdf vi中执行js

2024-09-29 21:35:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我已将html呈现为字符串,该字符串将作为PDF响应返回

class ReportFileResponse(FileResponse):

    def __init__(self, report, output_format):
        ....... # queries
        if output_format == 'pdf':
            super(ReportFileResponse, self).__init__(streaming_content=my_pdf_str,
                                                 content_type='application/pdf')

问题是字符串中包含一些肯定需要执行的js(修改一些块)。它在浏览器中工作(作为html),但不在PDF响应中执行。有没有办法执行JS代码

我考虑使用Selenium并执行JS代码。但我知道当你需要进入页面时该怎么做。但就我而言,我不能这么做。我无法转到该页,因为我已呈现html

至少我需要进行像getElementsByClassName这样的查询,并且可以访问属性

另外,对于渲染,我们使用django weasyprint


Tags: 字符串代码selfformatoutputpdfinitdef

热门问题