0

I'm building a site that provides Windows software that users can download. I want to retrieve text on another page.

Software Review Page (e.g: 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.

Download Page (e.g. 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.

I use Wordpress, how do I do this with Javascript or PHP. Can anyone help me, thanks in advance.

0

You're talking about scraping, which is generally an unreliable method of getting data, especially if you don't control the other page.

However, in PHP, once you retrieve the download page with something like wp_remote_get, you can use a regular expression to extract the pieces you need with preg_match_all.

$response = wp_remote_get( 'domain.com/download-page/' );
$page = wp_remote_retrieve_body( $response );
$regexp = '/developed by <strong>(.*?)<\/strong>.*?version is <strong>(.*?)<\/strong>/';
preg_match( $regexp, $page, $matches );
echo $matches[1]; // Jim
echo $matches[2]; // 25.0.8

Basically, each of the (.*?) parts captures the content that appears in that part of the pattern, and puts it in an array called $matches. Note that any change to how the developer and version are presented on the download page will likely break this pattern, so be careful.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.