繁体   English   中英

如何使用 PHP 从特定 url 的源代码中抓取值?

[英]How can I scrape the values from the source code of a particular url with PHP?

在 url 的源代码里面我想一下我可以看到这个:

 <div class="price"> 22.96€ </div>

这是我创建的 php 文件,但它没有返回任何值:

 <?php $data_scraped = file_get_contents('https://www.example.com/es/busquedas/?type%5B%5D=steam&query=motogp+20'); $the_start = explode('<div class="price">',$data_scraped); $the_end = explode('</div>',$the_start[1]); echo $the_end[0]; ?>

任何帮助将非常感激

您的问题看起来类似于在PHP中使用simple_html_dom进行 web 抓取的问题。

使用 simple_html_dom 重构您的代码:

<?php
require 'simple_html_dom.php';

$html = file_get_html('https://www.example.com/es/busquedas/?type%5B%5D=steam&query=motogp+20');
$price = $html->find('div[class=price]');

echo $price->plaintext."<br>";
?>

暂无
暂无

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

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