【问题标题】:jQuery - Pull content from another websitejQuery - 从另一个网站拉取内容
【发布时间】:2017-03-16 09:55:15
【问题描述】:

是否可以仅使用 JS/jQuery 从另一个网站提取内容?例如:

在 StackOverflow 上检索带有 html 标记的问题的数量。
该号码位于div 中的http://stackoverflow.com/questions/tagged/html 上,类为summarycount al

【问题讨论】:

  • 可能,但极不可能,因为网站需要启用 CORS,而很少有人会这样做。在这种情况下,您将被同源策略阻止。如果您想可靠地从第三方站点抓取数据,则必须在服务器端进行

标签: javascript jquery html


【解决方案1】:

尝试在其他网站中打开网站:

 <div> 
    <object type="text/html" data="http://validator.w3.org/" width="800px" height="600px" style="overflow:auto;border:5px ridge blue">
    </object>
 </div>

<script>
    $("#mydiv")
        .html('<object data="http://your-website-domain"/>');
</script>

如果你只想获得价值,而不显示:

 $( "#yourElement" ).load( "http://stackoverflow.com/questions/tagged/html #summarycount al" );

http://api.jquery.com/load/
可能需要将其放入 ajax 中。

【讨论】:

    猜你喜欢
    • 2015-01-07
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    • 2018-06-15
    • 1970-01-01
    相关资源
    最近更新 更多