我正在尝试使用 pdfkit 使用 Python 将一些网页保存为 PDF。上周它工作得很好(所以,我想这不是我的编码错误)。现在,该网站更改了一些导致“坏网关”问题的广告。我认为这可能是因为一些网络信标。当 pdfkit 尝试将页面另存为 PDF 时,我收到以下错误代码:
Warning: A slow script was stopped
Error: Failed to load https://sync-eu.connectad.io/syncer/1,
with network status code 301 and http status code 502 - Error
downloading https://sync-eu.connectad.io/syncer/1 - server
replied: Bad Gateway
我想保存的页面源代码中的脚本可能会导致错误:
<script type="text/javascript">
var ss=(function(){var pixelUrls=['https://sync-eu.connectad.io/syncer/1'];var MINS=60*1000;var SMARTSYNC_CALLBACK='serverbidCallBids';var SYNC_COOKIE_TTL=0*MINS;var SYNC_COOKIE='sb_ss';var pixelsInFlight=[];var inSecure=window.location.protocol.indexOf('s')<0;function createPixel(src){var p=document.createElement('iframe');p.setAttribute("height","0px");p.setAttribute("width","0px");p.setAttribute("border","0");p.setAttribute("frameBorder","0");p.setAttribute("style","position:absolute;");p.onerror=function(){return this.style.display="none";};p.setAttribute("src",src);if(window[SMARTSYNC_CALLBACK]){p.onload=function(){var i=pixelsInFlight.indexOf(src);if(i>=0){pixelsInFlight.splice(i,1);}
if(!pixelsInFlight.length){window[SMARTSYNC_CALLBACK]();}};pixelsInFlight.push(src);}
document.body.appendChild(p);}
function createCookie(){if(document.cookie.indexOf(SYNC_COOKIE)<0){var date=new Date();date.setTime(date.getTime()+ SYNC_COOKIE_TTL);return(document.cookie=SYNC_COOKIE+"; expires="+ date.toUTCString()+"; path=/"||1);}}
if(createCookie()){for(var i=0;i<pixelUrls.length;i++){var pixelUrl=pixelUrls[i];if(inSecure||pixelUrl.match(/^https:/)){createPixel(pixelUrl);}}}else if(window[SMARTSYNC_CALLBACK]){window[SMARTSYNC_CALLBACK]();}});var waitForDOM=function(evt){if(evt.target.readyState==="interactive"){ss();}}
document.addEventListener('readystatechange',waitForDOM,false);
</script>
问题是 pdfkit 保存了 PDF,但由于错误,它中止了循环,因此只保存了一页而不是大约十页。
如果有人可以帮助我解决这个问题,那就太好了。