且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从另一个网站通过ID获取Element

更新时间:2023-01-08 16:12:41

如果您可以访问其他站点并且存在Access-Control-Allow-Origin标头,则可以像这样使用jQuery:

If you have access to the other site and the Access-Control-Allow-Origin header is present, then jQuery can be used like this:

$.get('https://***.com/questions').then(function (html) {
    // Success response
    var $mainbar = $(html).find('#mainbar');
    document.write($mainbar.html());
}, function () {
    // Error response
    document.write('Access denied');
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>