PHP如何抓取网页面数据 并存入数据库中~~?

feixianking 2006-07-25 09:28:35
PHP如何抓取网页面数据 并存入数据库中~~?

麻烦有经验的前辈给个例子~~
...全文
1326 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zairwolfb 2006-07-29
  • 打赏
  • 举报
回复
开了远程url了么
wlypostman 2006-07-28
  • 打赏
  • 举报
回复
handle = fopen("http://www.example.com/", "r");//fopen
我用的是php4.4.2 apache 2.55上面的语句让apache死了。
其他用4。4。2的朋友有这个问题吗
5。1。4正常。
pt2519515 2006-07-28
  • 打赏
  • 举报
回复
关注
zeroleonhart 2006-07-27
  • 打赏
  • 举报
回复
I recommended to use file_get_contents().
feixianking 2006-07-27
  • 打赏
  • 举报
回复
用 file_get_contents 和 fsockopen哪个会好点呢?我读的是几十个页面~`
「已注销」 2006-07-26
  • 打赏
  • 举报
回复
file_get_contents -- 将整个文件读入一个字符串
说明
string file_get_contents ( string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]]]] )


和 file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。如果失败,file_get_contents() 将返回 FALSE。

file_get_contents() 函数是用来将文件的内容读入到一个字符串中的首选方法。如果操作系统支持还会使用内存映射技术来增强性能。

注: 如果要打开有特殊字符的 URL (比如说有空格),就需要使用 urlencode() 进行 URL 编码。

注: context 参数可以用 NULL 来忽略。


preg_match -- 进行正则表达式匹配
说明
int preg_match ( string pattern, string subject [, array matches [, int flags]] )



insert into tb (content) values ('$ar[1]');
把你收到的数据 丢到数据库里面的sql语言,如果你什么都不会那就一个一个慢慢学
wlypostman 2006-07-26
  • 打赏
  • 举报
回复
我用的是php 4.4.2 ,apache 2.55 使用file_get_contents($url)。c++2005报告异常。
版本问题???
mouzhi 2006-07-26
  • 打赏
  • 举报
回复
关注!
anshenghao 2006-07-26
  • 打赏
  • 举报
回复
一楼的不是已经给出代码了么
$str = file_get_contents($url);//打开你要抓取信息的页面
preg_match_all( '/.../' , $str , $ar );//利用正则匹配你要抓取的有用信息
insert into tb (content) values ('$ar[1]');//插入数据库~~~
xian222 2006-07-26
  • 打赏
  • 举报
回复
我也不懂哦
谁能有全代码?
期待............
zeroleonhart 2006-07-26
  • 打赏
  • 举报
回复
file_get_contents is available in PHP 5.
if you use PHP4,use the codes above.
lantersen 2006-07-26
  • 打赏
  • 举报
回复
你试试
$handle = fopen("http://www.example.com/", "r");//fopen
$contents = fread($handle, filesize ($filename));
fclose($handle);
再分析你得到的文件
上面的(PHP 3, PHP 4, PHP 5)都可用
颓废的老猫 2006-07-25
  • 打赏
  • 举报
回复
file_get_contents($url)
zeroleonhart 2006-07-25
  • 打赏
  • 举报
回复
$str = file_get_contents($url);
preg_match_all( '/.../' , $str , $ar );
insert into tb (content) values ('$ar[1]');

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧