简体   繁体   English

使用JavaScript解析网页中的文本?

[英]Parsing text from webpage in JavaScript?

I am learning JavaScript and what I want to do is search for keywords from a text-based website, given a URL. 我正在学习JavaScript,我想做的是从给定URL的基于文本的网站中搜索关键字。

An example website would just contain text like: 一个示例网站将只包含以下文本:

"a" : "nice"
"b" : "nope"
"a" : "try again"
"c" : "whatever"

Where I'd just like to find "a" and store what it is connected to. 我想在哪里找到“ a”并存储它所连接的内容。 What should I look for in JavaScript that would let me do something like this? 我应该在JavaScript中寻找什么让我做这样的事情?

Another example of "text-based" website: http://graph.facebook.com/zuck “基于文本的”网站的另一个示例: http : //graph.facebook.com/zuck

这是使用来自Facebook的GRAPH API的JSON-但是,您需要使用facebook API来获得它,这里是一个教程

The content you want to parse is so called JSON. 您要解析的内容称为 JSON。 You can parse JSON either using eval() (not advised) or some library (there are plenty of them). 您可以使用eval() (不建议使用)或某些库(有很多库eval()来解析JSON。

The bigger problem is how are going to get this data? 更大的问题是如何获取这些数据? If you want to load this script directly from Facebook, you can't use AJAX because of same origin policy. 如果您想直接从Facebook加载此脚本,则由于相同的原始策略,您不能使用AJAX。

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

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