我目前正在使用一个简单的 html dom 来抓取一个网站,我抓取的部分内容是:图像、链接和文本。现在我需要完成的是将抓取的数据保存到我的本地 PC 或数据库中。有没有办法可以使用 php 完成此任务?
强制将这些内容立即下载到我的 PC 或数据库中。
如果您认为有必要,将上传我的代码。先感谢您...
编辑:这是我的代码...
include("../dom/simple_html_dom.php");
if (isset($_POST['submit']))
{
if ($_POST['word1'] != ""){
//posts of the search query
$word1 = $_POST['word1'];
$items = array('url'=>'https://www.example.com/mobile-phones/?q='.str_replace(' ','+',$word1)."/",'img'=>'.image-wrapper img','brand'=>'h2.title span.brand','name'=>'h2.title span.name','price'=>'span.price-box','link'=>'section.products a.link');
$site = new simple_html_dom();
$currentImg = '';
$currentItemBrand = '';
$currentItemName = '';
$currentLink = '';
$currentPrice = '';
$counter = 0;
$number = -1;
$site->load_file($items['url']);
$currentImg = array();
$currentItemBrand = $site->find($items["brand"]);
$currentItemName = $site->find($items["name"]);
$currentLink = $site->find($items["link"]);
$currentPrice = $site->find($items["price"]);
foreach($site->find($items["img"]) as $element) {
$counter2++;
//initializing array objects
if($counter2 % 2 == 0 && $counter2 < 42)
{
$number++;
$currentImg = $element[$number]->src;
$currentItemName[$number]->plaintext;
$currentItemBrand2[$number]->plaintext;
$currentLink[$number]->href;
$currentPrice[$number]->plaintext;
}
}
// My Database Code
$insertSQL = "INSERT INTO items (img, name, link, price, brand) VALUES ('$currentImg', '$currentItemName', '$currentItemLink','$currentPrice','$currentItemBrand')";
mysqli_select_db($elecom_connect,$database_elecom_connect);
$Result1 = mysqli_query($elecom_connect,$insertSQL) or die(mysqli_error($elecom_connect));
exit();
}
}
}
?>
我对这段代码的问题是它只将图像的引用保存到数据库中......我想要的是下载所有文件数组,然后将它们存储在我的数据库中......我有点对如何做到这一点感到困惑......将感谢您的建议或代码块。