我正在尝试从网站中提取源代码,并希望将其保存在wamp服务器上的文本文件中。所以请帮助我。
它不是很复杂,你可以通过调用file_get_contents()来获取文件的内容,这包括网络上的文件。然后,您只需要将内容写入文件,并使用php提取.html源并将其保存在文本文件中即可。
<?php
// Open a webpage
$homepage = file_get_contents('http://www.example.com/');
// echo the homepage to see the content.
echo $homepage;
// Set the filename
$file = 'hp.txt';
// Write the contents back to the file
file_put_contents($file, $homepage);
?>
希望这是你需要的。