php抓取网站商城数据库 php获取其他网站的cookie( 二 )


file_get_contents();参数是对方的URL地址 , 这个函数返回是一个字符串你想要的东西就在这个字符串中了
接下来就可以针对这个字符串做处理了,说下思路 , 正如你这个问题想获取到航班号起飞时间,在这个网页中应该有很多相同的标签元素,它们都有共同点,用
用正则表达式preg_match();或者是
preg_match_all();这两个函数它们都返回一个数组,这个数组存的就是你要的航班号和起飞时间,那么相同信息的数组就会出现了,然后在对这个数组进行分析找到你要的某个值或全部的值
获取信息要用到的3个函数是:
file_get_contents();
preg_match();
preg_match_all();
php怎么抓取其它网站数据可以用以下4个方法来抓取网站 php抓取网站商城数据库的数据php抓取网站商城数据库:
1. 用 file_get_contents 以 get 方式获取内容:
【php抓取网站商城数据库 php获取其他网站的cookie】?
$url = '';
$html = file_get_contents($url);
echo $html;
2. 用fopen打开urlphp抓取网站商城数据库,以get方式获取内容
?
$url = '';
$fp = fopen($url, 'r');
stream_get_meta_data($fp);
$result = '';
while(!feof($fp))
{
$result .= fgets($fp, 1024);
}
echo "url body: $result";
fclose($fp);
3. 用file_get_contents函数,以post方式获取url
?
$data = https://www.04ip.com/post/array(
'foo'='bar',
'baz'='boom',
'site'='',
'name'='nowa magic');
$data = https://www.04ip.com/post/http_build_query($data);
//$postdata = https://www.04ip.com/post/http_build_query($data);
$options = array(
'http' = array(
'method' = 'POST',
'header' = 'Content-type:application/x-www-form-urlencoded',
'content' = $data
//'timeout' = 60 * 60 // 超时时间(单位:s)
)
);
$url = "";
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
4、使用curl库php抓取网站商城数据库,使用curl库之前 , 可能需要查看一下php.ini是否已经打开php抓取网站商城数据库了curl扩展
$url = '';
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
关于php抓取网站商城数据库和php获取其他网站的cookie的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

推荐阅读