在此简要介绍之后提供了一个jsFiddle Demo。
您正在使用的当前产品页面包含太多数据,只是为了获取价格。
最好使用 Flipkart.com 移动图书网站,因为这样加载速度更快。
参考1:http://www.flipkart.com/m/books
由于您的应用程序必须已经在使用图书的 pid 号,您可以查询移动网页搜索!您问题中的链接适用于 pid 的 9780224060875 的书
参考2:http://www.flipkart.com/m/search-all?query=9780224060875
在该页面上,您可以看到图书价格在 Span Tag 内,其中 Class Name 为 sp。
<!-- Fragment of product price format -->
<div id="productpage-price">
<p>
Price: <del> Rs. 350</del>
<span class="sp">Rs. 263</span>
</p>
</div>
然后,使用 jQuery,你可以像这样得到你需要的价格数据:
// Begin section to show random methods to use HTML values
// Get the HTML of "Rs. 263" and store it in variable as a string.
var priceTextAndLabel = $('#productpage-price').find('span.sp').text();
// Get the HTML of "Rs. 263" and slice off the first 4 characters of "Rs. " leaving "263" only.
// Adjust the .slice() if possiable that number is after decimal point. Example: "Rs.1000"
var priceText = $('#productpage-price').find('span.sp').text().slice(4);
// As above but convert text string of "263" to a number (to allow JavaScript Math if req.).
// The value 10 seen below reflects decimal base 10 (vs, octal(8) example) for .parseInt();
var priceNumber = parseInt($('#productpage-price').find('span.sp').text().slice(4),10);
// Firefox with Firebug Console will show BLACK characters for "Rs. 263" since it's a "string".
console.log( priceTextAndLabel );
// Firefox with Firebug Console will show BLACK characters for "263" since it's a "string".
console.log( priceText );
// Firefox with Firebug Console will show BLUE characters for "263" since it's a "number".
console.log( priceNumber );
// End section to show random method to use HTML values
好的,现在是关键部分...您一直在等待的部分...这就是如何在您的目标(甚至网页)中使用 Flipkart.com 搜索 URL。
可悲的答案是你不能。他们不仅禁止它,还阻止它。这意味着您不能 iframe 网页,甚至不能使用 AJAX 加载搜索 URL。
为了说明上述失败,这里有一个 jsFiddle Demo,当使用浏览器控制台查看时,将显示 AJAX 连接完成后没有获得任何内容。
参考3:jsFiddle flipkart.com Demo
推荐的解决方案:这里只有一个真正的选择。使用具有可用 API 的书店。该 API 可能具有用于特权访问的 API 密钥,可让您成为合法的商店代表。
也许他们最终会提供 API。现在,他们有一个Mobile App Store 用于收藏 MP3。看到 MP3 如何反映有声读物,他们也为图书提供移动应用商店可能只是时间问题。