我正在尝试使用以下代码提取车辆 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/