python - 在pdf视图中执行js
问题描述
我已将 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
并有权访问属性
PS 对于渲染我们使用 django-weasyprint
解决方案
推荐阅读
- sql - 数据库如何建模投资关系
- c# - 没有执行的 Http PostAsync
- string - 创建排序组 ID 而不对组进行排序
- android - Kotlin:需要'XXX',找到:Int
- angular - Angular 2 中的 Summernote
- acumatica - 将自定义操作添加到 GI Mass Actions 下拉列表
- typescript - 如何导入打字稿中定义的枚举?
- ms-access - 如何在从第一个表中删除数据时将数据从一个表附加到另一个表
- excel - ADODB.Connection & ADODB.Recordset - 用户定义类型未定义
- wordpress - Wordpress:我在 wp-content/themes/mytheme/function.php 中自动添加了一个代码