banner
 
Home Page
Daily News
Tin Viet Nam

 
Mobile Version
 
Home
 
Saigon Bao.com
Saigon Bao 2.com
Mobile
Directory
 
Liên Lạc - Contact
 
Liên Lạc - Contact
 
 
 
News
 
China News
SaigonBao Magazine
United States
World News
World News - Index
 
America News
 
Brazil
Canada
Mexico
South America
United States
 
Europe News
 
Europe
France
Germany
Russia
United Kingdom
 
Middle East News
 
Middle East
Afghanistan
Iran
Iraq
Saudi Arabia
Syria
 
 
Disclaimer
SaigonBao.com

All rights reserved
 
 
 
 
Diem Bao industry lifestyle
 
science - mobile - computer - Internet - Defence
 
 
 
   
 
africa - asia - europe - middle east - south america
 
Asia News (Tablet)
Asia News - Asia Business News - Australia - Cambodia - China - Daily News - India - Indonesia
Japan - Korea - Laos - Malaysia - Philippines - Singapore - Taiwan - Thailand - Vietnam
 

World News & Asia News
Asia Pacific - Europe news - Newsroom - Southeast Asia - Top Stories - US News
World News - World News Map - World Economy

 
 
 
 

PHP code that uses Simple HTML DOM to scrape data from multiple websites

AI Chat of the month - AI Chat of the year
 
An example PHP code that uses Simple HTML DOM to scrape data from multiple websites and save the results to a file called "scrap-data":
 

<?php
require_once('simple_html_dom.php');

// Define URLs to scrape
$urls = array("https://www.example.com", "https://www.another-example.com");

// Create empty array to hold scraped data
$scraped_data = array();

// Loop through each URL and scrape data
foreach ($urls as $url) {
// Send HTTP request to website and get response
$response = file_get_html($url);

// Parse HTML content of response using Simple HTML DOM
$dom = str_get_html($response);

// Extract relevant data from HTML using Simple HTML DOM's methods
// In this example, we are just extracting the page title
$page_title = $dom->find('title', 0)->innertext;

// Add extracted data to array of scraped data
array_push($scraped_data, $page_title);
}

// Write scraped data to file
$file = fopen("scrap-data.txt", "w");
foreach ($scraped_data as $data) {
fwrite($file, $data . "\n");
}
fclose($file);
?>

 
 
This code first defines an array of URLs to scrape, then uses a loop to iterate over each URL, sending an HTTP request and using Simple HTML DOM to extract relevant data from the HTML response. In this example, we are just extracting the page title for each URL, but you could modify the code to extract other data as well. The extracted data is then added to an array called "scraped_data". Finally, the code writes the contents of the "scraped_data" array to a text file called "scrap-data.txt".
 
 
 
Home Page
 
 
News
 
ABC
AFP
AP News
BBC
CNN
I.B. Times
Newsweek
New York Times
Reuters
Washington Post
 
 
Asia News
 
Asia
Asia Pacific
Australia
Cambodia
China
Hong Kong
India
Indonesia
Japan
Korea
Laos
Malaysia
New Zealand
North Korea
Philippines
Singapore
Taiwan
Thailand
Vietnam