如何在数据库
问题描述:
地狱朋友如何在数据库
我需要从这里
"http://www.drf.com/race-results/BHP/USA/2012-06-23/D"
获取比赛的结果,并且希望在我的数据库 来存储我需要获取所有记录获取来自其他网页和存储内容对于比赛1,比赛中2,race3等
请给我建议,我使用此代码 但它显示我整版我想只有特定信息
<?php
$ch = curl_init();
//Fetch the timeline
curl_setopt($ch, CURLOPT_URL, 'http://www.drf.com/race-results/BHP/USA/2012-06-24/D');
//send data via $_GET
//curl_setopt($ch, CURLOPT_GET, 0);
//do not return the header information
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
//If SSL verification is needed. Delete if not needed
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
//Give me the data back as a string... Don't echo it.
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Warp 9, Engage!
$content = curl_exec($ch);
//Close CURL connection & free the used memory.
curl_close($ch);
?>
答
Curl将返回网站的HTML代码,这是预期的。
转到实际站点,确定结果显示在哪里,div。然后使用PHP DOM解析器提取特定部分的数据,或者甚至可以提取字符串(简单但效率低,不推荐)。
从部分地带HTML标签,并保存所需要的数据,
答
我会建议使用Goutte库。它可以让你用记录良好的API刮擦和分析远程站点。你甚至可以关注链接并提交表单。从文档
实例:
use Goutte\Client;
$client = new Client();
与请求()方法提出请求:
$crawler = $client->request('GET', 'http://www.symfony-project.org/');
该方法返回一个履带式对象(Symfony的\元器件\ DomCrawler \履带)。
点击链接:基于CSS类和输出文本
$link = $crawler->selectLink('Plugins')->link();
$crawler = $client->click($link);
提取数据:
$nodes = $crawler->filter('.error_list');
if ($nodes->count())
{
die(sprintf("Authentification error: %s\n", $nodes->text()));
}
printf("Nb tasks: %d\n", $crawler->filter('#nb_tasks')->text());
你好谢谢回复我尝试这个,但显示我的错误, – user1485421