admin管理员组文章数量:1336380
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/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=".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=""><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/download-page/ page when clicking on the "Download (24MB)" button.
Download Page (e.g. domain/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.
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/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/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/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/download-page/ page when clicking on the "Download (24MB)" button.
Download Page (e.g. domain/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.
Share Improve this question asked Jun 6, 2020 at 2:43 R.M. RezaR.M. Reza 1417 bronze badges1 Answer
Reset to default 0You'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/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.
本文标签: phpHow To Get HTML Eelement From Another Page
版权声明:本文标题:php - How To Get HTML Eelement From Another Page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742371121a2462259.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论