如何从一个网页中提取元素以显示在另一个网页上 [英] How to pull an element from one webpage to display on another
问题描述
我正在处理一个网站,以显示来自另一个网站的一些详细信息.具体来说,我有一个想要显示的元素.我可以获取元素的 xpath 或 css 路径,我想用它来在不相关网站的 HTML 框中显示元素的值.
I'm working on a website to display some details from another website. Specifically I have an element I wish to display. I can get the elements xpath or css path, and I'd like to use this to display the value of the element in HTML box on a unrelated website.
我对此很陌生,所以我的问题真的很基本,我确定以前有人问过它,但我只是不知道要使用什么搜索词.我已经查找了我所能查找的内容,但我不确定我找到的内容是否可以在 HTML 框中使用(我尝试过但失败了,但我不确定这是我的错误还是应用程序的错误)方法错误).
I'm rather new to this so my question is really this basic, I'm sure it's been asked before but I just don't know what search terms to use. I've looked up what I can but I'm unsure if what I have found can be used in a HTML box (I've tried and failed, but I'm unsure if that's an error on my part or the application of the wrong method).
XPath: //*[@id="box2-server-status"]/div[3]/div[1]/div[1]/img
CSS 路径:
#box2-server-status > div.box2-content > div:nth-child(4) > div.server-status-indicator > img
欢迎任何带有指南的帮助/链接!
Any help/link with guides welcome!
推荐答案
看看这个,如果这对你有帮助..
Take a look at this, if that is what can be of help to you..
我得到了这个页面..
I got this page..
https://mkdizajn.github.io/my-colors/
我正要从这个页面中提取标题:
and I'm about to pull the title from this page:
http://mkdizajn.github.io/about/
如果您在该页面上打开检查器并在控制台"中输入此代码(如果我有时间并将其添加到源代码中;)
If you open inspector on that page and enter this code in 'console' (of if I got time and add it there in the source ;)
var content;
jQuery.ajax({
url: 'https://mkdizajn.github.io/about/',
success: function(data){
content = data;
var body = jQuery( content ) ;
alert( body.find('h1').text() ) ;
}
})
您必须以警报的形式从第二页获取内容......请注意该页面来自同一个域,这非常重要
you will have to get content from second page in the form of alert.. .. take a note that page is from that same domain, that is very important
https://mkdizajn.github.io/my-colors/
hth, k
这篇关于如何从一个网页中提取元素以显示在另一个网页上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!