Php Can';不能让preg_match为网页抓取工作
我这里有一些代码,但我不能让它工作。有人能帮我吗Php Can';不能让preg_match为网页抓取工作,php,html,regex,web-scraping,Php,Html,Regex,Web Scraping,我这里有一些代码,但我不能让它工作。有人能帮我吗 $file_string = file_get_contents('URL'); $search = "<tr><th> <a href=''>Data_name</a></th><td>(.*)</td></tr>"; preg_match($search, $file_string, $title); $title_out = $title[1];
$file_string = file_get_contents('URL');
$search = "<tr><th> <a href=''>Data_name</a></th><td>(.*)</td></tr>";
preg_match($search, $file_string, $title);
$title_out = $title[1];
echo $title_out;
$file\u string=file\u get\u contents('URL');
$search=“(*)”;
预匹配($search,$file\u string,$title);
$title_out=$title[1];
回声$title_out;
看看@Touki说了什么-但这可能会帮助您解决将来可能遇到的任何正则表达式问题:
(.*)
看起来像是非常精确的字符串。确保空白正确(制表符、空格、新行等)。您似乎还缺少一个超链接,不确定这是否是有意的相反,看看什么不起作用,有错误吗?第2行末尾缺少一个“
”;
”;如果必须使用正则表达式,请发布正在搜索的数据示例和一些预期匹配/不匹配的数据。能否显示您试图从中删除数据的页面的html内容?更不用说PHP中的正则表达式需要分隔符。