Skip to content

Instantly share code, notes, and snippets.

@cherenkov
Created January 24, 2011 20:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherenkov/793917 to your computer and use it in GitHub Desktop.
Save cherenkov/793917 to your computer and use it in GitHub Desktop.
Yahoo Pipesを使ってクロスドメイン通信でAmazonから目次情報を取得するサンプル。http://q.hatena.ne.jp/1294562027
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>
$(function() {
var isbn = ['4774127833', '4873113792', '4822248372'],
amz_url = '';
for(var i = 0, n = isbn.length; i < n; i++) {
amz_url = 'http://www.amazon.co.jp/gp/product/toc/' + isbn[i];
(function(j) {
$.ajax({
type: "get",
dataType: "jsonp",
url: "http://pipes.yahoo.com/poolmmjp/page_loader?url=" + amz_url + "&_render=json&_callback=?",
success: function(json) {
var doc = $(json.value.items[0].description);
var book_title = doc.find('#btAsinTitle').text()
var book_link = $('<a>').attr('href', 'http://www.amazon.co.jp/gp/product/' + isbn[j] + '?tag=amzac-22').text(book_title);
var toc = doc.find('.bucket .content > p').css({"font-size":"10px"});
$('<div>').append(book_link, toc, '<hr>').appendTo('#contents');
}
});
})(i);
}
});
</script>
</head>
<body>
<div id="contents"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment