unable to scrape content from a website

前端 未结 5 2229
清酒与你
清酒与你 2020-12-06 13:03

I am trying to scrap some content from a website but the code below is not working(not showing any output). here is the code

$url=\"some url\";
$otherHeader         


        
5条回答
  •  有刺的猬
    2020-12-06 13:54

    Yes, you are missing something very basic: It's XHTML, so you must register (and use!) the proper namespace before you can expect to get results.

    $xpath->registerNamespace('x', 'http://www.w3.org/1999/xhtml');
    
    $path1="//x:body/x:table[4]/x:tbody/x:tr[3]/x:td[4]";
    $path2="//x:body/x:table[4]/x:tbody/x:tr[1]/x:td[4]";
    
    $item1=$xpath->query($path1);
    $item2=$xpath->query($path2);
    

提交回复
热议问题