我正在尝试使用以下代码提取车辆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”标签的标签td
旁边th
的标签(并避免一些不必要的祖先依赖):
//td[preceding-sibling::th = 'Vehicle ID']
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句