我制作了自定义共享按钮,并想要添加口袋计数。
如果你在浏览器中打开这个链接https://widgets.getpocket.com/v1/button?count=vertical&url=http://google.com,你会看到口袋按钮计数器(例如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>
)与jQuery.ajax()
或其他东西(js)?
对不起,我是手机用户。你应该能够使用jQuery的"load()"函数来发出GET请求。
该函数接受一个url和一个回调,一旦请求被处理,将从口袋中返回html:
$.load(myURL, function(data){
var dom = $(data).html()
var pocket = dom.find('pocket selector')
});
一旦你可以访问"dom",查询按钮,然后使用"text()"来获取它可能是我要走的路线!