哪位帮我解决一下这个简单的关于采集的问题 <?phpecho file_get_contents("http://www.163.com");?> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 谢谢楼上的回复不过一般的采集程序都是用的 file_get_contents 这个函数吗?FOPEN应该怎么写呢? 用xmlhttp协议远程获取,你可以用GOOGLE搜索下,代码很多!'----------远程获取内容,并将内容存在本地电脑上,包括任何文件!----------'---------------利用xmlhttp和adodb.stream,酷!绝对原创!-----------------'On Error Resume Next'Set the content type to the specific type that you are sending.'Response.ContentType = "IMAGE/JPEG"'-------------------------------定义输出格式----------------------------- Path=request.querystring("p")sPath = Pathif left(lcase(path),7) <> "http://" then '-------------如果前面没有http就是本地文件,交给LocalFile处理------------LocalFile(path)else'--------------------否则为远程文件,交给RemoteFile处理------------------RemoteFile(Path)end if'Response.Write err.Des cription sub LocalFile(Path)'-------------------如果为本地文件则简单的跳转到该页面-------------------Response.Redirect PathEnd SubSub RemoteFile(sPath)'-------------------------处理远程文件函数------------------------------FileName = GetFileName(sPath)'-------------GetFileName为把地址转换为合格的文件名过程-------------FileName = Server.MapPath("/UploadFile/Cache/" & FileName)Set objFso = Server.CreateObject("s cripting.FileSystemObject")'Response.Write fileNameif objFso.FileExists(FileName) Then'--------------检查文件是否是已经访问过,如是,则简单跳转------------Response.Redirect "/uploadfile/cache/" & GetFileName(path)Else'----------------否则的话就先用GetBody函数读取----------------------'Response.Write Patht = GetBody(Path)'-----------------用二进制方法写到浏览器上--------------------------Response.BinaryWrite tResponse.Flush'-----------------输出缓冲------------------------------------------SaveFile t,GetFileName(path)'------------------将文件内容缓存到本地路径,以待下次访问-----------End if Set objFso = NothingEnd SubFunction GetBody(url) '-----------------------本函数为远程获取内容的函数---------------------'on error resume next'Response.Write urlSet Retrieval = CreateObject("Microsoft.XMLHTTP") '----------------------建立XMLHTTP对象-----------------------------With Retrieval .Open "Get", url, False, "", "" '------------------用Get,异步的方法发送-----------------------.Send 'GetBody = .ResponseTextGetBody = .ResponseBody'------------------函数返回获取的内容--------------------------End With Set Retrieval = Nothing 'response.Write err.Des cription End FunctionFunction GetFileName(str)'-------------------------本函数为合格化的文件名函数-------------------str = Replace(lcase(str),"http://","")str = Replace(lcase(str),"//","/")str = Replace(str,"/","")str = replace(str,vbcrlf,"")GetFileName = strEnd Functionsub SaveFile(str,fName)'-------------------------本函数为将流内容存盘的函数-------------------'on error resume nextSet objStream = Server.CreateObject("ADODB.Stream")'--------------建立ADODB.Stream对象,必须要ADO 2.5以上版本---------objStream.Type = adTypeBinary'-------------以二进制模式打开-------------------------------------objStream.Openobjstream.write str'--------------------将字符串内容写入缓冲--------------------------'response.Write fnameobjstream.SaveToFile "c:\inetpub\myweb\uploadfile\cache\" & fName,adSaveCreateOverWrite'--------------------将缓冲的内容写入文件--------------------------'response.BinaryWrite objstream.Read objstream.Close()set objstream = nothing'-----------------------关闭对象,释放资源-------------------------'response.Write err.Des cription End sub%> 同样谢谢楼上的回复但是我找的是PHP的代码类似DEDECMS或者其他的文章系统中的采集模块中的那种因为我的DEDECMS在该服务器上用不了,所以想找到原因,谢谢 wys444(wys444) ,DEDE是用的 FOPEN 啊,不是 file_get_contents 我是想测试一下DEDE为什么不能采集 file_get_contents和fopen效果差不多的 多看manual。无非是读取内容,正则,原理都是一样的。 php.net/fopen 回 wys444(wys444) 效果是差不多的这一点我明白主要是 服务器上用 file_get_contents 可以正常读取远程网址,但是DEDECMS的采集就是用不了,所以我想用 FOPEN 检测一下是哪里出了问题哪位用FOPEN给我写下获取远程网址的小程序,谢了 PHP关于函数传中文值乱码的问题 关于程序在360浏览器下蛋疼的问题 请问同一浏览器会话每次刷新Session ID都不一样? 标题:php也能实现url重写 PHP 中 mail 函数的使用 PHPSESSID直接显示在浏览器地址栏里,会有会有副作用? 操作txt的问题,狂送分 一个小问题 在PHP中调用函数如: fdf_create(void);总是出现Call to undefined function: fdf_create() 哪个库定议了它? dom指的是什么 怎么用preg_replace php设计网站过程
不过一般的采集程序都是用的 file_get_contents 这个函数吗?
FOPEN应该怎么写呢?
'---------------利用xmlhttp和adodb.stream,酷!绝对原创!-----------------
'On Error Resume Next
'Set the content type to the specific type that you are sending.
'Response.ContentType = "IMAGE/JPEG"
'-------------------------------定义输出格式----------------------------- Path=request.querystring("p")
sPath = Path
if left(lcase(path),7) <> "http://" then
'-------------如果前面没有http就是本地文件,交给LocalFile处理------------
LocalFile(path)
else
'--------------------否则为远程文件,交给RemoteFile处理------------------
RemoteFile(Path)
end if
'Response.Write err.Des cription sub LocalFile(Path)
'-------------------如果为本地文件则简单的跳转到该页面-------------------
Response.Redirect Path
End SubSub RemoteFile(sPath)
'-------------------------处理远程文件函数------------------------------
FileName = GetFileName(sPath)
'-------------GetFileName为把地址转换为合格的文件名过程-------------
FileName = Server.MapPath("/UploadFile/Cache/" & FileName)
Set objFso = Server.CreateObject("s cripting.FileSystemObject")
'Response.Write fileName
if objFso.FileExists(FileName) Then
'--------------检查文件是否是已经访问过,如是,则简单跳转------------
Response.Redirect "/uploadfile/cache/" & GetFileName(path)
Else
'----------------否则的话就先用GetBody函数读取----------------------
'Response.Write Path
t = GetBody(Path)
'-----------------用二进制方法写到浏览器上--------------------------
Response.BinaryWrite t
Response.Flush
'-----------------输出缓冲------------------------------------------
SaveFile t,GetFileName(path)
'------------------将文件内容缓存到本地路径,以待下次访问-----------
End if
Set objFso = Nothing
End SubFunction GetBody(url)
'-----------------------本函数为远程获取内容的函数---------------------
'on error resume next
'Response.Write url
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
'----------------------建立XMLHTTP对象-----------------------------
With Retrieval
.Open "Get", url, False, "", ""
'------------------用Get,异步的方法发送-----------------------
.Send
'GetBody = .ResponseText
GetBody = .ResponseBody
'------------------函数返回获取的内容--------------------------
End With
Set Retrieval = Nothing
'response.Write err.Des cription
End FunctionFunction GetFileName(str)
'-------------------------本函数为合格化的文件名函数-------------------
str = Replace(lcase(str),"http://","")
str = Replace(lcase(str),"//","/")
str = Replace(str,"/","")
str = replace(str,vbcrlf,"")
GetFileName = str
End Functionsub SaveFile(str,fName)
'-------------------------本函数为将流内容存盘的函数-------------------
'on error resume next
Set objStream = Server.CreateObject("ADODB.Stream")
'--------------建立ADODB.Stream对象,必须要ADO 2.5以上版本---------
objStream.Type = adTypeBinary
'-------------以二进制模式打开-------------------------------------
objStream.Open
objstream.write str
'--------------------将字符串内容写入缓冲--------------------------
'response.Write fname
objstream.SaveToFile "c:\inetpub\myweb\uploadfile\cache\" & fName,adSaveCreateOverWrite
'--------------------将缓冲的内容写入文件--------------------------
'response.BinaryWrite objstream.Read
objstream.Close()
set objstream = nothing
'-----------------------关闭对象,释放资源-------------------------
'response.Write err.Des cription
End sub
%>
但是我找的是PHP的代码
类似DEDECMS或者其他的文章系统中的采集模块中的那种因为我的DEDECMS在该服务器上用不了,所以想找到原因,谢谢
我是想测试一下DEDE为什么不能采集
无非是读取内容,正则,原理都是一样的。
php.net/fopen
效果是差不多的这一点我明白
主要是 服务器上用 file_get_contents 可以正常读取远程网址,但是DEDECMS的采集就是用不了,所以我想用 FOPEN 检测一下是哪里出了问题哪位用FOPEN给我写下获取远程网址的小程序,谢了