php的采集程序,怎么截取网页中的链接及标题
发布网友
发布时间:2022-04-19 20:44
我来回答
共1个回答
热心网友
时间:2023-06-22 02:14
<?php
if (! empty($_POST['url'])) {
$url = trim($_POST['url']);
$c = file_get_contents($url);
$titlepartner = preg_match_all('/<title>(.*)<\/title>/isU', $c, $matches);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<form method="post">
<table>
<tr>
<th>URL</th>
<td><input type="text" name="url" value="<?php echo $url; ?>">(完整的网址)</td>
<td><input type="submit" value="开始"></td>
</tr>
</table>
</form>
<?php
if (! empty($_POST['url'])) {
echo "<br />";
echo "<table border='1' width='500px' height='50px'>";
echo "<tr>";
echo "<th>TITLE</th>";
echo "<td>{$matches[1][0]}</td>";
echo "</tr>";
echo "</table>";
}
?>
</body>
</html>
简单的写了一下,主要是写正则,去匹配读取过来的html代码字符串,有什么不明白的可以私密我,纯手打,望采纳!