1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- --公共文件
- --获取table长度
- function table_length(t)
- if type(t)~="table" then
- return 0
- end
- local len=0
- for _,_ in pairs(t) do
- len=len+1
- end
- return len
- end
- --保存网页为pdf文件
- function save_page_to_pdf(tab_title,tab_href,dir,title)
- local filename = ""
- if string.find(title,"2024年")~=nil then
- filename = "2024_"..title.."__浏览器生成.pdf"
- elseif string.find(title,"2023年")~=nil then
- filename = "2023_"..title.."__浏览器生成.pdf"
- else
- filename = "2022_"..title.."__浏览器生成.pdf"
- end
- print("准备生成网页pdf",filename)
- local ok2 = browser_print2pdf(tab_href,1000*60*20,dir..filename)
- print("生成pdf",ok2)
- end
- --页面清理元素,只保留中心元素
- local remote_body_el_without_js=[[
- var hold_el = document.querySelector("%s");
- function removeAllChildren(parent) {
- var children = parent.childNodes;
- for (var i = children.length - 1; i >= 0; i--) {
- parent.removeChild(children[i]);
- }
- }
- removeAllChildren(document.body);
- document.body.appendChild(hold_el);
- ]]
- --页面清理元素,只保留中心元素
- function clear_page_el(tab_title,tab_href,timeout,css_selector)
- local js = string.format(remote_body_el_without_js, css_selector)
- local ok, ret = browser_executejs(tab_title,tab_href,timeout,0, js)
- return ok,ret
- end
|