php Web-Scraping Divs with Class不显示图像
我正在网上网络上的报纸在线外部URL,使用此平面PHP,类block__Item
,现在由其他类和图像组成
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$url = "https://www.repubblica.it";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument('1.0', 'utf-8');
@$doc->loadHTML($content);
$classname="block__item";
$finder = new DomXPath($doc);
$spaner = $finder->query("//*[contains(@class, '$classname')]");
foreach ($spaner as $value) {
echo $doc->saveXML($value);
}
/?>
,图像未显示;我在页面上有空间,即URL,但看不到图像。
我尝试了这个
$images = $finder->query("(//img/@src)");
foreach ( $images as $image) {
$print = $doc->saveXML($image);
echo $print;
}
,这给了我页面末尾的所有图像;
我尝试了联合收割机
foreach (array_combine($spaner, $images) as $value => $image){
echo $value, $image;
}
,但收到错误。 我也同时尝试了 Query 类和IMG,但没有。
拜托,有人可以帮我吗?
I'm web-scraping a newspaper online, external url, with this plane php, a class block__item
, which is compose of other classes and images
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$url = "https://www.repubblica.it";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument('1.0', 'utf-8');
@$doc->loadHTML($content);
$classname="block__item";
$finder = new DomXPath($doc);
$spaner = $finder->query("//*[contains(@class, '$classname')]");
foreach ($spaner as $value) {
echo $doc->saveXML($value);
}
/?>
Now, images are not displayed; I have the space in the page, the url, but I can't see the image.
I tried with this
$images = $finder->query("(//img/@src)");
foreach ( $images as $image) {
$print = $doc->saveXML($image);
echo $print;
}
and this gave me all the images at the end of the page;
I tried with combine
foreach (array_combine($spaner, $images) as $value => $image){
echo $value, $image;
}
but I receive error.
I tried also with query class and img in the same time, but nothing.
Please, anyone could help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论