chetankchandak Posted March 14, 2014 Share Posted March 14, 2014 I want to extract current data from a particular website(http://www.ncdex.com/MarketData/LiveFuturesQuotes.aspx) and then show it on my website. I want to extract only if the Data is "Chana" or else move to next line or stop. Because the website keeps on updating and the field(Chana) always changes its rows. Please help me. <html> <body> <?php $html = file_get_contents('http://www.ncdex.com/MarketData/LiveFuturesQuotes.aspx'); //get the html returned from the following url libxml_use_internal_errors( true); $doc = new DOMDocument; $doc->loadHTML( $html); $xpath = new DOMXpath( $doc); $node4a = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[1]/a')->item( 0); $node4b = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[7]')->item( 0); $node4c = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[8]')->item( 0); $src4 = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[7]/img/@src')->item( 0); $node4d = $xpath->query( '//*[@id="ctl00_ContentPlaceHolder3_dgLiveFuturesQuotes"]/tbody/tr[11]/td[2]')->item( 0); echo $node4a->textContent; // This will print **Chana** echo $node4b->textContent; echo $node4c->textContent; echo $img1; echo $src4->nodeValue; echo $img2; echo "|"; echo $node4d->textContent; echo "<br>"; ?> </html> Link to comment https://forums.phpfreaks.com/topic/286956-using-xpath-to-get-specific-data-from-other-website/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.