Advertisement
basictomonokai

Google feed APIが無くなって大慌てテスト中

Dec 3rd, 2015
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" /><title>rss受信テスト</title>
  5.  
  6. <script src='https://code.jquery.com/jquery-2.1.4.min.js'></script>
  7. <script>
  8. $.ajax({
  9.     url: 'http://rfobasic.freeforums.org/feed.php',
  10.     type: 'get',
  11.     dataType: 'xml',
  12.     timeout: 5000,
  13.     success: function(xml, status) {
  14.         if (status === 'success') {
  15.                         // alert('bbb');
  16.             var row = 0;
  17.             var data = [];
  18.             var nodeName;
  19.                         var hizuke = [];
  20.                         var aaa = '';
  21.                         //        alert('ccc');
  22.             $(xml).find('item').each(function() {
  23.                                 // alert('ccd');
  24.                 data[row] = {};
  25.                 $(this).children().each(function() { // 子要素を取得
  26.                     nodeName = $(this)[0].nodeName; // 要素名
  27.                     data[row][nodeName] = {}; // 初期化
  28.                     attributes = $(this)[0].attributes; // 属性を取得
  29.                     for (var i in attributes) {
  30.                         data[row][nodeName][attributes[i].name] = attributes[i].value; // 属性名 = 値
  31.                                                 console.log(row,nodeName,attributes[i].name);
  32.                                                 console.log(data[row][nodeName][attributes[i].name]);
  33.                     }
  34.                                         if (nodeName == "dc:date") {
  35.                                           //alert('aaa');
  36.                                           hizuke[row] = $(this).text();
  37.                                         }
  38.                                         if (nodeName == "pubDate") {
  39.                                           //alert('aaa');
  40.                                           hizuke[row] = $(this).text();
  41.                                         }
  42.                     data[row][nodeName]['text'] = $(this).text();
  43.                                         // alert(row,' ',nodeName,' ',attributes[i].name);
  44.                                         // console.log(row,' ',nodeName,' ',attributes[i].name);
  45.                                         // console.log(data[row][nodeName]['text']);
  46.                 });
  47.                 row++;
  48.             });
  49.             $('#rss').wrapInner('<ul></ul>');
  50.             for (i in data) {
  51.                 $('#rss').find('ul').append('<li>' + data[i].title.text + '</li>');
  52.             }
  53.              for (i in data) {
  54.                             aaa = aaa + data[i].title.text;
  55.                             aaa = aaa + '@x@';
  56.                             aaa = aaa + data[i].link.text;
  57.                             aaa = aaa + '@x@';
  58.                             aaa = aaa + '【@feedname@】';
  59.                             aaa = aaa + '@x@';
  60.                             aaa = aaa + $('<div>').html(data[i].description.text).text();
  61.                             aaa = aaa + '@x@';
  62.                             aaa = aaa + hizuke[i];
  63.                             aaa = aaa + '@y@';
  64.  
  65.                 //console.log(data[i].link.text);
  66.                             //console.log(data[i].title.text);
  67.                             // console.log(data[i].description.text);
  68.                             // console.log(data[i].description.text.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g,''));
  69.                             //console.log($('<div>').html(data[i].description.text).text());
  70.                             // console.log(data[i].pubDate.text);
  71.                             // console.log(data[i].dc\\:date.text);
  72.                             //console.log(hizuke[i]);
  73.                            
  74.              }
  75.                          alert(aaa);
  76.         }
  77.     }  
  78. });
  79. </script>
  80.  
  81. </head>
  82. <body>
  83.  
  84. <div id="rss"></div>
  85.  
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement