How do I get text from a website using PHP?

后端 未结 7 2020
北海茫月
北海茫月 2020-12-31 11:33

So, I\'m working on a PHP script, and part of it needs to be able to query a website, then get text from it.

First off, I need to be able to query a certain website

7条回答
  •  时光取名叫无心
    2020-12-31 11:48

    I would do a dom search, take a look at http://www.php.net/manual/es/domdocument.load.php Domxpath might be very useful too: http://php.net/manual/en/class.domxpath.php

    $doc = new DOMDocument;
    $doc->load("http://mysite.com");
    $xpath = new DOMXpath($doc);
    $elements = $xpath->query("*/div[@id='yourTagIdHere']");
    

提交回复
热议问题