PHP can be used to scrape web page data; the most common approach is to use the cURL extension library. Here is a simple example:
// 创建一个cURL资源
$ch = curl_init();
// 设置URL和其他cURL选项
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 抓取URL并把它传递给浏览器
$data = curl_exec($ch);
// 关闭cURL资源,并释放系统资源
curl_close($ch);
// 输出抓取的数据
echo $data;This code fetches the content from http://www.example.com/ and displays it in the browser. You can use various cURL options to perform different data scraping tasks—such as setting request headers, sending POST requests, or configuring a proxy server. If you need to parse an HTML page, you can use PHP's DOM extension library or a third-party library (e.g., Simple HTML DOM Parser) for this purpose.