在我的网页中显示另一个网页的单个元素

时间:2017-09-13 18:17:29

标签: html dynamic element scrape

到目前为止,Google只提供了如何在其他网页中显示整个网页 - 我知道该怎么做。但是,我需要从我自己的另一个网页显示一个特定的元素值。我找不到任何有关如何在html页面中执行此类操作的信息。我知道如何通过vbscript进行webscraping,但这涉及.vbs文件和抓取Internet Explorer。我不认为这种方法适用于此。我需要能够在我的页面中动态拉取和显示其他页面文本。

例如,要在页面中简单地显示Google搜索按钮文本“Google搜索”,我尝试过(我知道这是错误的,但仅作为示例...):

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
    </head>

<script language="VBScript">

Function getText()

Set IE = CreateObject("internetexplorer.application")
IE.Visible = true
IE.Navigate "https://www.google.com/?gws_rd=ssl"
Do While IE.Busy or IE.ReadyState <> 4:Loop

For each a in ie.getElementsByTagName("input")
    if a.name = "btnk" then 
        content.innerhtml = a.value 
    end if
next

End function
</script>

    <body>      
        <div>
            <a onclick="getText()" href="#">Click Me</a>
        </div>
        <div id="content">
            Webpage text element will display here...
        </div>
    </body>

</html>

知道我怎么能够实现这个目标吗?

编辑**第二次尝试(不工作):

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
         <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    </head>

<script>
Function getText()
$( "#content" ).load( "https://www.google.com/?gws_rd=ssl input#btnk" );

</script>
    <body>      
        <div>
            <a onclick="getText()" href="#">Click Me</a>
        </div>
        <div id="content">
            Webpage text element will display here...
        </div>
    </body>

</html>

0 个答案:

没有答案