使用php将每个url指向目录的图像抓取
我有图像抓取的代码,但我在这里试图解决的是一些问题:使用php将每个url指向目录的图像抓取,php,Php,我有图像抓取的代码,但我在这里试图解决的是一些问题: 替换此$the_site=“url”使用我的输入type=“text” 因此,我不想把url放在代码上,而是想把url放在我的输入上 我想创建多个文件夹和链接,而不是在页面上重复5次相同的代码,将每个url指向一个目录 我的代码是关于从页面下载图像并将其保存到文件夹中,所以我想将所有内容放在一个php标记中 这是我的密码 <?php $the_site = "url"; $the_tag = "div"; # $
$the_site=“url”代码>使用我的输入type=“text”
因此,我不想把url放在代码上,而是想把url放在我的输入上
<?php
$the_site = "url";
$the_tag = "div"; #
$the_class = "slides";
$html = file_get_contents($the_site);
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//'.$the_tag.'[contains(@id,"'.$the_class.'")]/img') as $item) {
$img_src = $item->getAttribute('src');
//print $img_src."\n"; Ignore This
//copy($img_src,'C:\xampp\htdocs\grabIMG\download'); Ignore This
$img_name = end(explode("/",$img_src));
echo $img_name.' has downloaded<br />';
$img_content = file_get_contents($img_src);
$fp = fopen(" folder/".$img_name,"w");
fwrite($fp,$img_content);
fclose($fp);
}
?>