简体   繁体   English

如何从我的 HTML 页面从另一个网站获取信息?

[英]How to get info from another website from my HTML page?

What is needed is as follows:所需内容如下:

I have an HTML webpage and I need to access another website and get something from its source code.我有一个 HTML 网页,我需要访问另一个网站并从其源代码中获取一些东西。

I want to run something like我想运行类似的东西

link = "http://www.google.com"; doc.querySelectorAll('#courses_menu > ul > li > a'); // Apply on the link.

to get what I need from the link and use it从链接中获取我需要的内容并使用它

However, I am using Jetpack slide bar.但是,我使用的是 Jetpack 滑杆。

Does it have to do anything with HTTP requests?它与 HTTP 请求有什么关系吗?

I think you could pull the entire page using an Ajax request, put the content in a hidden iframe, and then manipulate the DOM in the iframe.我认为您可以使用 Ajax 请求拉动整个页面,将内容放在隐藏的 iframe 中,然后在 iframe 中操作 DOM。 Something like (here using the jQuery framework)类似的东西(这里使用 jQuery 框架)

 <iframe id="holder" style="display: none"> <script type="text/javascript"> $("#holder").load("http://www.google.com",function () { $link = $("#holder").contents().find("#courses_menu > ul > li > a"); }); </script>

I recommend using a Ajax (eg jquery) with a PHP proxy on the same Webserver.我建议在同一 Web 服务器上使用 Ajax(例如 jquery)和 PHP 代理。 The Proxy loads the the remote webpage and is then available under the same domain.代理加载远程网页,然后在同一域下可用。

Don't forget to protect the proxy against abuse.不要忘记保护代理免受滥用。

Have a page which will have a result of your query "doc.querySelectorAll('#courses_menu > ul > li > a');"有一个页面将包含您的查询结果“doc.querySelectorAll('#courses_menu > ul > li > a');”

Add an IFrame in your page, set the src as the page which has the above result.在你的页面中添加一个 IFrame ,将 src 设置为具有上述结果的页面。

<iframe src='pagenamewhichhasresult'/>

You can include other website content in your html document using an iframe.您可以使用 iframe 在 html 文档中包含其他网站内容。 However, due to the same original policy, you cannot have script from your domain affect content from another domain.但是,由于相同的原始策略,您的域中的脚本不能影响另一个域中的内容。 In other words, you can't write some javascript to manipulate the content of some other web page you put in an iframe.换句话说,您不能编写一些 javascript 来操作您放入 iframe 的其他一些 web 页面的内容。 The script would have to come from that domain as well.该脚本也必须来自该域。

If you want to insert another website page or data the如果您想插入另一个网站页面或数据

Just use:-只需使用:-

 <iframe src="https://libcon.in/" frameborder="0" scrolling="yes"></iframe>

want more then use this Link想要更多然后使用此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM