symfony - 使用 Guzzle 从 html 中提取信息

标签 symfony xpath web-crawler guzzle

我正在尝试使用以下代码提取车辆 ID:

    $client = new Client();
    $request = $client->get('http://www.truck1.eu/_TEN_auto_1522980_Truck_Chassis_MAN_TGA_18_320_BL_Platou_9_80m_lang_manuelles_Getriebe_Euro_4_Motor.html',  ['allow_redirects' => false]);

    $html = $request->getBody(true);

    $crawler = new Crawler();
    $crawler->addContent($html);
    print $crawler->filterXPath('//*[@id="content"]/div/div[2]/table/tbody/tr[2]/td')->text();

但由于某种原因我无法让它工作。我正在使用 Symfony 的 Guzzle 和 DomCrawler。

最佳答案

尝试使用此 XPath 来获取包含“车辆 ID”标签的 th 旁边的 td(并避免一些不必要的祖先依赖性):

//td[preceding-sibling::th = 'Vehicle ID']

关于symfony - 使用 Guzzle 从 html 中提取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27251314/

相关文章:

python - 爬虫将数据更新到数组,在循环内yield

python - 循环中的 Scrapy 调用请求

php - 覆盖 FOSUserBundle 表单类型时无法加载类型 "XYZ"错误

javascript - symfony 中 PHP 文件的路径

java - 搜索第 n 个命中时无法使用 Selenium 找到现有元素

xpath - XPath查询Google表格ImportXML以从页面获取YouTube视频URL

ios - iOS 中的网页抓取

symfony - 迭代并打印 Twig 中范围内的所有日期

php - 我需要将 SQL native 放在查询生成器 Doctrine2 中

sql-server - SQL Server : How do I check if an element attribute of an xml node contains a specific string?