Christopher
Christopher

Reputation: 3469

Extract info from html with Guzzle

I'm trying to extract Vehicle ID with this code:

    $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();

But for some reason i can't get this working. I'm using Guzzle and DomCrawler from Symfony.

Upvotes: 2

Views: 1443

Answers (1)

kjhughes
kjhughes

Reputation: 111521

Try this XPath to grab the td next to the th containing the 'Vehicle ID' label (and to avoid some unnecessary ancestral dependencies):

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

Upvotes: 2

Related Questions