Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Symfony';domscrawler组件_Php_Symfony - Fatal编程技术网

Php 使用Symfony';domscrawler组件

Php 使用Symfony';domscrawler组件,php,symfony,Php,Symfony,我需要在本网站上刮取具有“CR”的数值,例如: 不幸的是,我无法使用DomCrawler筛选器方法找到解决方案 任何有经验的Symfony用户都可以帮助我吗?或者给我一些建议 这是我使用xpath方法得到的结果: $crawler->filterXPath('//div/center/table/tbody/tr/td[contains(., 'CR')]')->text() 更新我设法通过以下方式获取了所有CR: //td/font[contains(., 'CR')]

我需要在本网站上刮取具有“CR”的数值,例如:

不幸的是,我无法使用DomCrawler筛选器方法找到解决方案

任何有经验的Symfony用户都可以帮助我吗?或者给我一些建议

这是我使用xpath方法得到的结果:

 $crawler->filterXPath('//div/center/table/tbody/tr/td[contains(., 'CR')]')->text()
更新我设法通过以下方式获取了所有CR:

//td/font[contains(., 'CR')]
但我需要的是数字


谢谢

爬虫程序类似于SimpleXML和jQuery。如果你不熟悉它们,你将很难弄清楚如何获取内容。您不必显式地使用
xpath
来获取内容。您可以使用
过滤器
(与jQuery类似,即
过滤器('body>.my_class')


因此,这不是一个让开发人员免费为他们工作的地方。发布您的代码、您迄今为止的尝试以及您遇到的错误。仅使用curl和regex即可轻松完成。我对xpath不熟悉或没有任何经验。这是我使用xpath方法$crawler->filterXPath得到的('//div/center/table/tbody/tr/td[contains(,'CR')])->text();
$url = '...';

$crawler = new Crawler(file_get_contents($url));

$crawler->filterXPath("//td/font[contains(., ' CR')]")->each(function(Crawler $node, $i){
    $string = filter_var($node->parents()->first()->text(), FILTER_SANITIZE_URL);
    $string = str_replace('CR', ' CR', $string);
    var_dump($string);
});