简体   繁体   English

加载外部网页并添加自定义标题并使用网页中的数据

[英]load external webpage and add custom header and use the data from webpage

I want to load a external webpage on my own server and add my own header. 我想在自己的服务器上加载外部网页并添加自己的标头。 Also i need to use the data from the external website like url and content (i need to search and find specific data, check if i got that data in my system and show my data in the header). 我还需要使用来自外部网站的数据,例如url和content(我需要搜索和查找特定数据,检查我的系统中是否有该数据并在标题中显示我的数据)。 The external webpage needs to be working (like the buttons for opening other pages, no new windows). 外部网页需要正常工作(例如用于打开其他页面的按钮,没有新窗口)。

I know i can play with .NET to create software but i want to create a website that will do the trick. 我知道我可以使用.NET来创建软件,但我想创建一个可以解决问题的网站。 Can this be done? 能做到吗? Php + iframe is to simple i think, that won't give me the data from external website and my server won't see changes in the external url (what i need). php + iframe很简单,我想这不会给我来自外部网站的数据,我的服务器也不会看到外部url的更改(我需要什么)。

If it's supposed to be client-side, then you can acquire the data necessary by using an Ajax request, parsing it in JavaScript and then just inserting it into an element. 如果应该是客户端,那么您可以通过使用Ajax请求来获取必要的数据,在JavaScript中对其进行解析,然后将其插入到元素中。 However you have to take into account that if the host doesn't support cross-origin resource sharing , then you won't be able to do it like this. 但是,您必须考虑到,如果主机不支持跨域资源共享 ,那么您将无法做到这一点。

Ajax page source request: get full html source code of page through ajax request through javascript Ajax页面源请求: 通过javascript通过ajax请求获取页面的完整html源代码

Parsing elements from the source: http://ajaxian.com/archives/html-parser-in-javascript (not sure if useful) 从源中解析元素: http : //ajaxian.com/archives/html-parser-in-javascript (不确定是否有用)

Changing the element body: 更改元素主体:

// data --> the content you want to display in your element
document.getElementById('yourElement').innerHtml = data;

Other approach (server-side though) is to "act" like a browser by faking your user-agent to some browser's and then using cUrl for example to get the source. 另一种方法(尽管在服务器端)是通过将用户代理伪装到某些浏览器上,然后像使用cUrl来获取源代码,从而像浏览器一样“起作用”。 But you don't want to fake it, because that's not nice and you would feel bad.. 但是您不想伪造它,因为那样不好,您会感到难受。

Hope it gets you started! 希望它能帮助您入门!

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

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