-1
試圖僅使用$.getJSON
和YQL從具有唯一名稱的類中提取文本。現在它會提取所有數據並去掉標籤。任何人都知道這是否可以實現?只想拉JSON類並非全部數據
function filterData(data){
// filter all the nasties out
// no body tags
data = data.replace(/<?\/body[^>]*>/g,'');
// no linebreaks
data = data.replace(/[\r|\n]+/g,'');
// no comments
data = data.replace(/<--[\S\s]*?-->/g,'');
// no noscript blocks
data = data.replace(/<noscript[^>]*>[\S\s]*?<\/noscript>/g,'');
// no script blocks
data = data.replace(/<script[^>]*>[\S\s]*?<\/script>/g,'');
// no self closing scripts
data = data.replace(/<script.*\/>/,'');
// the below doesn't work of course, but if I could use jQuery I would do as follows:
data = $(data).find('.count').text();
return data;
}
這裏是它拉JSON的一部分:
"div": [
{
"id": "store-page-rating",
"div": [
{
"id": "store-six-month-rating",
"div": {
"style": "float:left;",
"span": {
"class": "rating",
"img": {
"alt": "Rating 8.68/10",
"class": "stars fourhalf",
"src": "http://images4.resellerratings.com/CDN-1328669559/static/images/blankstar.gif",
"style": "width: 80px; height: 16px;",
"title": "Rating 8.68/10"
},
"span": [
{
"class": "count",
"content": "27"
},
我怎麼能只顯示「27」階級「計數」,而不是域上的所有數據?
如果你想拉只有1類(其中有27個的), DIV [0] .div [0] .div.span.span [0]。內容將返回27 – Jashwant 2012-02-08 05:21:42
你如何/在哪裏使用YQL,並做什麼? – salathe 2012-02-08 18:46:28