如何提取<pre> tag

时间:2017-08-19 12:45:04

标签: javascript html5 dom css-selectors getelementsbytagname

As a coding newbie I'm following a tutorial on the map function which gives this example

As a datasource we'll use HackerNews' big RSS feed and since we can treat RSS as > plain HTML, it's very simple to get started:

var titles = document.getElementsByTagName('title');

When I run this command I don't get anything back, when I inspect the page, I see that all the data and tags are enclosed inside of a top level tag. I can run document.getElementsByTagName('pre') which returns everything, but not the specific title tags.

Any help on understanding this and working around it would be useful.

1 个答案:

答案 0 :(得分:0)

事实证明,Chrome正在添加应用于数据的元素。在FireFox中,可以正确查看所有rss数据并继续学习本教程。

我不确定为什么一个浏览器呈现所有dom节点,而Chrome只是将它们隐藏在预标签中,但这就是查询在Chrome中不起作用的原因。