您好,欢迎访问一九零五行业门户网

php中get_meta_tags()、CURL与user-agent信息对比

下面来简单的介绍在php中get_meta_tags()、curl与user-agent信息对比情况,如果你对于这篇文章有兴趣可进入参考学习。
get_meta_tags()函数用于抓取网页中形式的标签,并装入一维数组,name为元素下标,content为元素值,上例中的标签可以获得数组:array('a'=>'1', 'b'=>'2')。其他标签不处理,并且此函数只处理到标签时截止,之后的也不再继续处理,不过
之前的还是会处理。user-agent是浏览器在向服务器请求网页时,提交的不可见的头信息的一部分。头信息是一个数组,包含多个信息,比如本地缓存目录,cookies等,其中user-agent是浏览器类型申明,比如ie、chrome、ff等。
今天在抓取一个网页的标签的时候,总是得到空值,但是直接查看网页源代码又是正常的,于是怀疑是否服务器设置了根据头信息来判断输出。先尝试使用get_meta_tags()来抓取一个本地的文件,然后这个本地文件将获取的头信息写入文件,结果如下(其中替换成了/,方便查看):
'192.168.30.205', 'path' => 'c:/program files/common files/netsarang;c:/program files/nvidia corporation/physx/common;c:/program files/common files/microsoft shared/windows live;c:/program files/intel/icls client/;c:/windows/system32;c:/windows;c:/windows/system32/wbem;c:/windows/system32/windowspowershell/v1.0/;c:/program files/intel/intel(r) management engine components/dal;c:/program files/intel/intel(r) management engine components/ipt;c:/program files/intel/opencl sdk/2.0/bin/x86;c:/program files/common files/thunder network/kankan/codecs;c:/program files/quicktime alternative/qtsystem;c:/program files/windows live/shared;c:/program files/quicktime alternative/qtsystem/; %java_home%/bin;%java_home%/jre/bin;', 'systemroot' => 'c:/windows', 'comspec' => 'c:/windows/system32/cmd.exe', 'pathext' => '.com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc', 'windir' => 'c:/windows', 'server_signature' => '', 'server_software' => 'apache/2.2.11 (win32) php/5.2.8', 'server_name' => '192.168.30.205', 'server_addr' => '192.168.30.205', 'server_port' => '80', 'remote_addr' => '192.168.30.205', 'document_root' => 'e:/wamp/www', 'server_admin' => 'admin@admin.com', 'script_filename' => 'e:/wamp/www/user-agent.php', 'remote_port' => '59479', 'gateway_interface' => 'cgi/1.1', 'server_protocol' => 'http/1.0', 'request_method' => 'get', 'query_string' => '', 'request_uri' => '/user-agent.php', 'script_name' => '/user-agent.php', 'php_self' => '/user-agent.php', 'request_time' => 1400747529,)?>
果然在数组中没有http_user_agent这个元素,apache在向另外一台服务器发送请求的时候是没有ua的。之后查了一下资料,get_meta_tags()函数没有伪造ua的能力,所以只能使用其他办法解决了。
后来使用curl来获取,就获取到了网页,不过使用上稍微麻烦一点,首先伪造ua,获取之后在使用正则表达式分析
伪造办法:
文章网址:
随意转载^^但请附上教程地址。
其它类似信息

推荐信息