Take a website with PHP and then navigate it using jQuery

I am creating a system in which I will need to capture the contents of a webpage using PHP and then parse it to extract specific tables, etc. Is there an easy way to do this using jQuery or would it be best to write a PHP function to retrieve data?

+3
source share
6 answers

jQuery has nothing to do with PHP and cannot be run without a browser, so you're out of luck there.

However, there is phpQuery that allows parsing the DOM with jQuery selectors!

+7
source

php php DOM xpath:

    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    $x = new DOMXPath($dom);
    // grab all tables with id of foo
    foreach($x->query("//table[@id='foo']") as $node)
    {
        // here is the html
                    echo $node->c14n();
                    // grab the containing text 
                    echo $node->textContent()
    }
+3

. jQuery JavaScript, , JavaScript-.

HTML XML, , HTML XHTML.

+1

http://sourceforge.net/projects/simplehtmldom/

:

// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all images
foreach($html->find('img') as $element)
       echo $element->src . '<br>';

// Find all links
foreach($html->find('a') as $element)
       echo $element->href . '<br>'; 
0

php, , curl, dom xpath.

, .

0

Source: https://habr.com/ru/post/1772924/


All Articles