简体   繁体   English

读取HTML文件以使用javascript生成数据

[英]Read HTML file to generate data using javascript

I got to read a number of HTML files, get its tags content and generate a report using these contents (eg day1.html has Simon, I need to read day1.html file, and get 'author' div content which is 'Simon' and generate my own report using this data). 我必须阅读许多HTML文件,获取其标签内容并使用这些内容生成报告(例如,day1.html具有Simon,我需要阅读day1.html文件,并获取“ author” div内容,即“ Simon”并使用此数据生成我自己的报告)。 How can I do it using Javascript? 如何使用Javascript进行操作? any help is highly appreciated. 非常感谢您的帮助。 Many thanks. 非常感谢。 An 一个

If you're not adverse to using jQuery you can use get() to load and parse an HTML document via JavaScript: 如果您不反对使用jQuery,则可以使用get()通过JavaScript加载和解析HTML文档:

jQuery.get('day1.html', function(html)) {
  var author_div_text_content = jQuery('DIV#author', html).text(); 
}

A sample working on the jsFiddle web site: jsFiddle网站上的示例:

http://jsfiddle.net/KCxDp/ http://jsfiddle.net/KCxDp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM