Загрузка...

Spare the site?

Thread in Backend created by header Dec 21, 2022. 270 views

  1. header
    header Topic starter Dec 21, 2022 157 Oct 20, 2019
    Каким инструментом можно парсить сайт с помощью php?
    Нужно отправить GET запрос и спарсить html
     
  2. мориц
    мориц Dec 21, 2022 5537 Oct 27, 2020
  3. Yooo_inactive6259585
    Чтобы спарсить HTML код, ты можешь использовать класс DOMDocument.
    Ниже пример:
    PHP
    <?php
    // Send the GET request and store the response as a string

    $html = file_get_contents('http://www.example.com/');

    // Create a new DOMDocument object

    $dom = new DOMDocument();

    // Load the HTML string into the DOMDocument object

    @$dom->loadHTML($html);

    // Use DOMXPath to query the DOMDocument object

    $xpath = new DOMXPath($dom);

    // Query the DOMDocument object and store the results in an array

    $elements = $xpath->query("//div[@class='example']");

    // Iterate over the array of elements and print the innerHTML of each element

    foreach ($elements as $element) {

    echo $element->innerHTML;

    }

    Этот код отправит запрос GET на указанный URL, спарсит HTML. Затем он выполнит итерацию по массиву элементов и выведет innerHTML каждого элемента.
     
    1. header Topic starter
  4. Экстази_неактив5264046
  5. Vulkong
    Vulkong Dec 22, 2022 Banned 2 Jul 4, 2022
    Curl либо готовые по типу DOMDocument
     
Loading...
Top