Php 使用curl_multi和preg_match_all输出网站,网站加载缓慢
我有一个使用curlmulti的脚本,它在多个网站上搜索内容。我想知道什么是一种更快的方式来输出每个网站的某些内容Php 使用curl_multi和preg_match_all输出网站,网站加载缓慢,php,curl,foreach,preg-match,Php,Curl,Foreach,Preg Match,我有一个使用curlmulti的脚本,它在多个网站上搜索内容。我想知道什么是一种更快的方式来输出每个网站的某些内容 <?php // Get the tables for 1 website preg_match_all("/\<tbody\>(.*?)\<\/tbody\>/is", $res[0], $matches ); foreach($matches[0] as $value) {
<?php // Get the tables for 1 website
preg_match_all("/\<tbody\>(.*?)\<\/tbody\>/is",
$res[0], $matches );
foreach($matches[0] as $value)
{
echo $value;
}
// Get the tables for site 2
preg_match_all("/\<div class=\"dealsListS\"\>(.*?)\<\/div\>/is",
$res[1], $matches );
foreach($matches[0] as $value)
{
echo $value;
}
// Get the tables for site 3
preg_match_all("/\<div class=\"city_save\"\>(.*?)\<\/div\>/is",
$res[2], $matches );
foreach($matches[0] as $value)
{
echo $value;
}
// Get the tables for site 4
preg_match_all("/\<div class=\"offer-stream\"\>(.*?)\<\/div\>/is",
$res[3], $matches );
foreach($matches[0] as $value)
{
echo $value;
}
?>
需要帮助,使网页不会加载太长时间。这只是我需要补充的少数内容 你能试试这个代码吗
<?php
function extract_data($html_code, $regex) {
$buffer="";
preg_match_all($regex, $html_code, $matches );
foreach($matches[0] as $value)
{
$buffer .= $value;
}
return $buffer;
}
// Get the tables for 1 website
$buffer = extract_data("/\<tbody\>(.*?)\<\/tbody\>/is", $res[0]);
// Get the tables for site 2
$buffer .= extract_data("/\<div class=\"dealsListS\"\>(.*?)\<\/div\>/is", $res[1]);
// Get the tables for site 3
$buffer .= extract_data("/\<div class=\"city_save\"\>(.*?)\<\/div\>/is", $res[2]);
// Get the tables for site 4
$buffer .= extract_data("/\<div class=\"offer-stream\"\>(.*?)\<\/div\>/is", $res[3]);
echo $buffer;
?>
不要使用正则表达式来解析HTML,请使用