Вот несколько методов с использованием примеров кода для получения цен на хостинг SiteGround:
-
Пример Python с использованием библиотеки BeautifulSoup:
import requests from bs4 import BeautifulSoup url = "https://www.siteground.com/shared-hosting.htm" response = requests.get(url) soup = BeautifulSoup(response.text, "html.parser") price_elements = soup.find_all("span", class_="sg-price") prices = [element.text for element in price_elements] print(prices) -
Пример PHP с использованием cURL и DOMDocument:
$url = "https://www.siteground.com/shared-hosting.htm"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $dom = new DOMDocument(); $dom->loadHTML($response); $priceElements = $dom->getElementsByTagName("span"); $prices = []; foreach ($priceElements as $element) { if ($element->getAttribute("class") === "sg-price") { $prices[] = $element->nodeValue; } } print_r($prices); -
Пример JavaScript с использованием Axios и Cheerio (Node.js):
const axios = require("axios"); const cheerio = require("cheerio"); const url = "https://www.siteground.com/shared-hosting.htm"; axios.get(url) .then(response => { const $ = cheerio.load(response.data); const priceElements = $(".sg-price"); const prices = []; priceElements.each((index, element) => { prices.push($(element).text()); }); console.log(prices); }) .catch(error => { console.log(error); });