简体   繁体   English

如何从另一个页面获取 HTML 元素

[英]How To Get HTML Eelement From Another Page

I'm building a site that provides Windows software that users can download.我正在建立一个网站,提供用户可以下载的 Windows 软件。 I want to retrieve text on another page.我想检索另一页上的文本。

Software Review Page (eg: domain.com/obs-studio/):软件评论页面(例如:domain.com/obs-studio/):

<ul class="software_facts">
    <li>
        <div class="dorat">
            <div class="labelimg">[thumbnail]</div> 
            <div class="wp-block-button is-style-squared">
                <form name="myform1" action="/download-page/" method="post"><input name="bode" type="hidden" value="https://github.com/obsproject/obs-studio/releases/download/25.0.8/OBS-Studio-25.0.8-Full-Installer-x64.exe"></form>
                <div class="wp-block-button__link has-background has-vivid-green-cyan-background-color" onclick="document.myform1.submit()">Download (24 MB)</div>
            </div>
        </div>
    </li>
    <li class="bg">
        <p class="labelnil">Nilai:</p>
        [kkratings]
    </li>
    <li>
        <p class="label">Version:</p>
        <p itemprop="softwareVersion">25.0.8</p>
    </li>
    <li class="bg">
        <p class="label">Publisher:</p>
        <p itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization"><span itemprop="name">Jim</span></p>
    </li>
    <li>
        <p class="label">Sistem Operasi:</p>
        <p itemprop="operatingSystem">Windows</p>
    </li>
    <li class="bg">
        <p class="label">Kategori Aplikasi:</p>
        <p itemprop="applicationCategory">Multimedia</p>
    </li>
    <li>
        <p class="label">Licence:</p>
        <p>Freeware</p>
    </li>
</ul>

The user is directed to the domain.com/download-page/ page when clicking on the "Download (24MB)" button.单击“下载 (24MB)”按钮时,用户将被定向到 domain.com/download-page/ 页面。

Download Page (eg domain.com/download-page/):下载页面(例如 domain.com/download-page/):

<p>OBS Studio was developed by <strong>Jim</strong>, the latest version is <strong>25.0.8</strong>.</p>

I want the " Jim " and " 25.0.8 " sections to change according to the software information that the user wants to download on the previous page.我希望“ Jim ”和“ 25.0.8 ”部分根据用户想要在上一页下载的软件信息进行更改。

I use Wordpress, how do I do this with Javascript or PHP.我使用 Wordpress,如何使用 Javascript 或 PHP 执行此操作。 Can anyone help me, thanks in advance.任何人都可以帮助我,提前谢谢。

In Software Review Page在软件评论页面

Use the input tag with hidden type to have publisher and software version values to send in the post method.使用带有隐藏类型的输入标签来让发布者和软件版本值在 post 方法中发送。

<ul class="software_facts">
<li>
    <div class="dorat">
        <div class="labelimg">[thumbnail]</div> 
        <div class="wp-block-button is-style-squared">
            <form name="myform1" action="/download-page/" method="post"><input name="bode" type="hidden" value="https://github.com/obsproject/obs-studio/releases/download/25.0.8/OBS-Studio-25.0.8-Full-Installer-x64.exe">

                <input name="publisher" type="hidden" value="Jim">
                <input name="softwareVersion" type="hidden" value="25.0.8">

            </form>
            <div class="wp-block-button__link has-background has-vivid-green-cyan-background-color" onclick="document.myform1.submit()">Download (24 MB)</div>
        </div>
    </div>
</li>
<li class="bg">
    <p class="labelnil">Nilai:</p>
    [kkratings]
</li>
<li>
    <p class="label">Version:</p>
    <p itemprop="softwareVersion">25.0.8</p>
</li>
<li class="bg">
    <p class="label">Publisher:</p>
    <p itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization"><span itemprop="name">Jim</span></p>
</li>
<li>
    <p class="label">Sistem Operasi:</p>
    <p itemprop="operatingSystem">Windows</p>
</li>
<li class="bg">
    <p class="label">Kategori Aplikasi:</p>
    <p itemprop="applicationCategory">Multimedia</p>
</li>
<li>
    <p class="label">Licence:</p>
    <p>Freeware</p>
</li>

In Download Page在下载页面

<p>OBS Studio was developed by <strong><?php echo $_POST['publisher']; ?></strong>, the latest version is <strong><?php echo $_POST['softwareVersion']; ?></strong>.</p>

Please note that I have sent the values in the superglobal variable called $_POST with the keys provided.请注意,我已经使用提供的键发送了名为$_POST的超全局变量中的值。 Use echo statements to print the values from these variables.使用 echo 语句打印这些变量的值。

you need create a crone job to update the software information table data by file_get_html the web page you want to grab the data from.您需要创建一个 cron 作业以通过file_get_html更新要从中获取数据的 web 页面的软件信息表数据。 Using file_get_html , the output will be an String, so create a DOM using it and extract your desired content from the DOM content and save to your database table使用file_get_html , output 将是一个字符串,因此使用它创建一个DOM并从DOM内容中提取您想要的内容并保存到您的数据库表

refer: reference to html dom paser参考:参考html dom paser

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

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