我想得到页面上的文字,和连接下的内容得到其余的图片,网站的头部和尾部都不要了,并且我想把如何得到的信息写入数据库中,小弟只明白一点
还指望各位指教:
<?php
$url="http://www.jjxww.com/html/list.aspx?cid=207";
$content=file_get_contents($url);
?>
解决方案 »
- 想学php,求指点
- 问下php的空值问题
- 用php截取另一个网页的内容,例如新闻小偷。求源码,几行即可。
- 用session来进行身份验证(php+mysql环境),我的程序有严重漏洞,help me!
- 查询的问题
- amaoking 请进!4.1.0 的 is_file() 函数竟然真的是个 BUG ……
- php在哪里能设置默认显示页,例如index.htm而不用在路径后再输入index.htm
- 请问板板 为什么有些字段索引后反而更加影响查询速度
- thinkphp初学者的疑问?
- 如何一个页面查询到的值传入另外一个页面的input中
- 高手指教——————获取网页里的所有邮箱地址
- jpgraph画柱状图,报错$bplotarray为空
$sql=mysql_query("insert into 表名(字段1)values('$content')")
if(mysql_affected_rows($sql)>0)
{
echo "<script>alert('恭喜您,添加成功!');location.href='#';</script>";
}
else
{
echo "<script>alert('不恭喜您,添加失败!');location.href='message.php';</script>";
}
?>不知道这样可行否
error_reporting(E_ALL ^ E_NOTICE);set_time_limit(0);
$htmldir = "./zhtml";
@mkdir($htmldir);
@chmod($htmldir,777);
$httpdir = "http://www.jjxww.com/html/";
$url = "{$httpdir}list.aspx?cid=207";
$html = file_get_contents($url);
$html = formathtml($html);
preg_match_all('~<a href="(show\.aspx\?.*?)"[^>]*?>(.*?)</a>~is',$html,$data);
$result=array();
foreach($data[1] as $key=>$item){
$result[$key]["href"]=$item;
}
foreach($data[2] as $key=>$item){
$result[$key]["title"]=$item;
}
//获取完整标题,本想在上一个preg_match_all里把标题给提取出来,却怎么提都是空。
foreach($data[0] as $key=>$rt){
preg_match_all('~title="(.*?)"~is',$rt,$tdata);
if($tdata[1][0]!="")$result[$key]["title"]=$tdata[1][0];
}
foreach($result as $key=>$query){
$nurl=$httpdir.$query['href'];
$html = file_get_contents($nurl);
$html = formathtml($html);
preg_match_all('~<hr/><div id="BodyLabel" class="content" style="display:block;padding:0px 10px">(.*?)</div><br/><br/><table width="97%" cellpadding="0" cellspacing="0" style="clear:both"><tr><td align="right"><table><tr><td>责任编辑~is',$html,$data);
$result[$key]["content"]=$data[1][0];
//写入数据库
$title = $result[$key]["title"];
$content = $result[$key]["content"];
/*
写入数据库
*/
//这里用写入文件测试
writeover($htmldir.'/'.$title.".txt",$content);
//break;
}function formathtml($html){
$html = preg_replace('/>(\s+)/','>',$html);
$html = preg_replace('/(\s+)</','<',$html);
$html = preg_replace('/(\s+)/',' ',$html);
$html = str_replace("\r\n",'',$html);
$html = str_replace("\t",'',$html);
return $html;
}function writeover($filename,$data,$method="rb+",$iflock=1,$check=1,$chmod=1){
touch($filename);
$handle = fopen($filename,$method);
$iflock && flock($handle,LOCK_EX);
fwrite($handle,$data);
$method=="rb+" && ftruncate($handle,strlen($data));
fclose($handle);
$chmod && @chmod($filename,0777);
}