Методы получения цен на веб-хостинг с примерами кода

Чтобы узнать стоимость веб-хостинга, вам необходимо взаимодействовать с API поставщика веб-хостинга или очистить его веб-сайт. Вот несколько способов добиться этого на разных языках программирования:

  1. Python с запросами и библиотеками BeautifulSoup:

    import requests
    from bs4 import BeautifulSoup
    url = "https://example.com/web-hosting-plans"
    response = requests.get(url)
    soup = BeautifulSoup(response.text, "html.parser")
    price_element = soup.find("span", class_="price")
    price = price_element.text.strip()
    print("The price of web hosting is:", price)
  2. JavaScript с Node.js и библиотекой Cheerio:

    const request = require('request');
    const cheerio = require('cheerio');
    const url = 'https://example.com/web-hosting-plans';
    request(url, (error, response, body) => {
    if (!error && response.statusCode === 200) {
    const $ = cheerio.load(body);
    const priceElement = $('.price');
    const price = priceElement.text().trim();
    console.log('The price of web hosting is:', price);
    }
    });
  3. PHP с cURL и DOMDocument:

    $url = 'https://example.com/web-hosting-plans';
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
    curl_close($curl);
    $dom = new DOMDocument();
    @$dom->loadHTML($response);
    $xpath = new DOMXPath($dom);
    $priceElement = $xpath->query('//span[@class="price"]')->item(0);
    $price = $priceElement->nodeValue;
    echo 'The price of web hosting is: ' . $price;

Обратите внимание, что в приведенных примерах кода предполагается, что у вас есть URL-адрес страницы планов веб-хостинга и что цена заключена в элемент HTML с классом или идентификатором «цена». Возможно, вам придется изменить код в зависимости от структуры целевой веб-страницы.