search
HomeBackend DevelopmentPHP Tutorial这个有关问题有点难,curl抓取不到页面

这个问题有点难,curl抓取不到页面。

本帖最后由 xroha 于 2015-03-07 15:57:23 编辑 百度经验里的url,如:http://jingyan.baidu.com/article/e2284b2b24eeb2e2e6118dfd.html

直接看页面源代码,是有文章数据。
但是用curl .都无法正常获取文章内容。
这是为什么?已经伪造了IP,来路,cookie等,但还是抓取不到。
注意:在本地可以抓取,但是上传到服务器就不行了,
测试了三个服务器,SAE,阿里云,商务中国的空间,都无法获取。
百度是通过什么防止抓取数据的?怎么破解?

以下是代码:
<br />function fcontents( $url, $timeout = 5, $referer = "" ){<br />    $t = parse_url($url);<br />    $ch = curl_init();<br />    $header = array (<br />        'User-Agent: Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.1.1916.153 Safari/537.36','X-FORWARDED-FOR:154.135.25.15', 'CLIENT-IP:154.135.25.15'<br />    );<br />    $cookie_jar = dirname(__FILE__)."/jy.cookie";<br />    curl_setopt($ch, CURLOPT_URL, $url);<br />    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);<br />    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);<br />    curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");   //构造来路 <br />    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);<br />    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);<br />    curl_setopt($ch, CURLOPT_HEADER, 0);<br />    $result = curl_exec($ch);<br />    curl_close($ch);<br />    return $result;<br />}<br />



------解决思路----------------------
他们都支持 curl 吗?
------解决思路----------------------
百度感知到你的IP访问频率很可疑
要么就是有复杂的cookie验证流程
------解决思路----------------------
1.如果本地可以,服务器不行。程序是没有问题的。
2.SAE,阿里云,商务中国的空间
这些都支持curl吗,有试试采集其他地址吗?
3.有可能这段时间这些服务器都采集百度,所以被屏蔽掉了。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

How do you optimize PHP applications for performance?How do you optimize PHP applications for performance?May 08, 2025 am 12:08 AM

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

What is dependency injection in PHP?What is dependency injection in PHP?May 07, 2025 pm 03:09 PM

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

Best PHP Performance Optimization TechniquesBest PHP Performance Optimization TechniquesMay 07, 2025 pm 03:05 PM

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

PHP Performance Optimization: Using Opcode CachingPHP Performance Optimization: Using Opcode CachingMay 07, 2025 pm 02:49 PM

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.