通过使用Java脚本循环显示不同的评论表



我有3个包含评论的表:

https://www.top2rotten-traders.co.uk/trader-view-review?i=1
https://www.top2rotten-traders.co.uk/trader-view-review?i=2
https://www.top2rotten-traders.co.uk/trader-view-review?i=3

我想在主页上的这些页面上的表格循环。

我通过将表变成图像来成功工作,但是我宁愿通过实际数据循环,而不必摆弄JPG文件等。

  <!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
  <script type="text/javascript">
    var index=0;
    function changeBanner(){ 
      [].forEach.call(document.images,function (v,i) { document.images[i].hidden = i!==index});
      index = (index+1) % document.images.length;
    }
    window.onload = function () {setInterval(changeBanner, 1000)};
  </script>
</head>
<body>
  <div id="wrapper">
    <div>
        <img src="http://blog.4pm.ie/wp-content/uploads/2013/01/Mona-Lisa1.jpg" width="900px" height="300px" />
      <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcRNdgz5xts4e3lP262ex-PaDSxoQoowWgOsJ124473AkFYx9SRauA" width="900px" height="300px" />
      <img src="http://cache.graphicslib.viator.com/graphicslib/media/5c/the-last-supper-mural-by-leonardo-da-vinci-santa-maria-photo_1344348-770tall.jpg" width="900px" height="300px" />
    </div>
  </div>
</body>
</html>

我希望在主页上看到1个表,每隔几秒钟循环到下一个表。

这是您可以获取表并将其放入网站的方式:

const urls = ["https://www.top2rotten-traders.co.uk/trader-view-review?i=1",
"https://www.top2rotten-traders.co.uk/trader-view-review?i=2", "https://www.top2rotten-traders.co.uk/trader-view-review?i=3" ]
for (const [index, url] of urls.entries()) {
  const html = fetch(url).then((response) => { 
    const parser = new DOMParser();
    const doc = parser.parseFromString(response.text());
    const table = doc.querySelector('#view-review');
    // make sure your don't have duplicate ids before inserting
    table.id += index;
    wrapper.querySelector('div').appendChild(table);
  })
}

当然,由于相同的原始策略,该示例在这里无法使用。

如果脚本仅在托管在同一域上的页面上运行。

最新更新