如何从Pocket Button获取Pocket计数器(使用jQuery)?

时间:2015-09-24 19:01:58

标签: javascript jquery pocket

我制作了自定义共享按钮,并希望向他们添加Pocket次。

如果您在浏览器中打开此链接https://widgets.getpocket.com/v1/button?count=vertical&url=http://google.com,则会看到带有计数器的Pocket按钮(例如,URL是google.com)。

这是一个简单的HTML文档:

<html><head>
<link rel="stylesheet" type="text/css" href="https://d7x5nblzs94me.cloudfront.net/v1/c/button.css?v=6">
<script type="text/javascript" src="https://d7x5nblzs94me.cloudfront.net/v1/j/shared.js?v=2"></script>
<style type="text/css"></style></head>
<body>

<div class="widget vertical pocket center">
    <a id="btn">
                <!-- 
        Please do not scrape this for the Pocket count. 
        It is not relible for you to use and will likely change. 
        Contact us at api@getpocket.com for an official API. 
        Thanks! 
        -->
        <span><em id="cnt">126775</em><i></i><u></u></span>
                <b></b>
    </a>
</div>

<script type="text/javascript">
var POCKET_DOMAIN = 'getpocket.com';
var iLi = true;

var btnData = {"mode":"viapocketbutton","ct":"b607befed1e75f78567281514cae33db78cbcab9","ctn":"ed82217ee621d17ee56ca091cd836e96149b7921","label":"pocket","count":"vertical","src":"","url":"http:\/\/google.com"};
</script>
<script type="text/javascript" src="https://d7x5nblzs94me.cloudfront.net/v1/j/button.js?v=5"></script>

</body></html>

如何使用<em id="cnt">...</em>或其他内容(js)解析此Pocket数(放在jQuery.ajax()上)?

1 个答案:

答案 0 :(得分:0)

原谅我,我在移动设备上。 您应该能够使用jQuery的'load()'函数发出GET请求。

该函数接受一个url和回调,一旦请求处理完毕,将从口袋中返回html:

$.load(myURL, function(data){
    var dom = $(data).html()
    var pocket = dom.find('pocket selector')
});

一旦你有权访问'thedom',查询按钮然后使用'text()'抓住它可能就是路径Id!