简体   繁体   中英

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.

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. What should I look for in JavaScript that would let me do something like this?

Another example of "text-based" website: http://graph.facebook.com/zuck

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

The content you want to parse is so called JSON. You can parse JSON either using eval() (not advised) or some library (there are plenty of them).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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