Home Backend Development PHP Tutorial Curl号称强大,却在抓花瓣网的首页时,如何也不能成功,求解!

Curl号称强大,却在抓花瓣网的首页时,如何也不能成功,求解!

Jun 13, 2016 am 10:30 AM
curl id quot

Curl号称强大,却在抓花瓣网的首页时,怎么也不能成功,求解!!!!!!!
一直用curl抓页面,十分方便,屡试屡爽,却在抓取花瓣网首页的一个看似简单的操作中,发现怎么也不能成功。

基本代码如下:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'http://huaban.com/');
//模拟蜘蛛
//curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');
//模拟普通浏览器
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)');
//可以不要cookie, 因为不登陆,能返回首页即可
//curl_setopt($ch, CURLOPT_USERAGENT, '');
//其实也可以不要来路,模拟直接输入地址的
curl_setopt($ch, CURLOPT_REFERER, 'http://huaban.com/');
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//curl_setopt($ch, CURLOPT_HEADER, 0); //输出header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_exec($ch); 
curl_close($ch);

我已经反复尝试不同的cookie header agent,都不能返回如同浏览器打开的那种可见页面,甚至尝试过 file_get_contents('http://huaban.com/'); 都没用。 返回的内容,绝大部分内容为js代码, 但之前成功抓取的页面,包括各种大小网站,也有js, 并不影响远程抓取和显示啊。 试了一天,百思不得其解,在csdn qq群里面也进行了讨论,有人说可能是curl不能运行js。 但现在哪个网站没有js代码能, 之前抓取的那些站,js也不在少数啊。没有一个失败的。。

实在不知道怎么解决,将这个问题丢出来,恳请高人作答。 到底是curl不行呢,还是这个网站太变态呢,还是方法不对呢?。。。。

------解决方案--------------------
这种优雅的小清新网站, 没JS还让它怎么存活在这个竞争惨烈的市场?
------解决方案--------------------
这个网站的特别之处就是它的绝大部分内容都是js动态生成的,通过js与后端程序交互不断的产生新内容
所以用curl抓取的只是它最初始的代码,也就是大段的js了
------解决方案--------------------
这是你要的数据吧?不知道你是怎么个抓包法
{"filter":"pin:category:all","pins":[{"pin_id":8447271,"user_id":394332,"board_id":1146189,"file_id":3483249,"file":{"farm":"farm1","bucket":"hbimg","key":"a1524741e8fae0916ba04c8d231f8ad23173ddb5baeff-rNFCpP","type":"image/jpeg","width":440,"height":5779,"frames":1},"media_type":0,"source":"weibo.com","link":"http://weibo.com/2134919185/yoVlDsGWs","raw_text":"小小灯泡大改造,你也来动手做一个吧~","text_meta":{},"via":2,"via_user_id":0,"original":null,"created_at":1340276725,"like_count":0,"comment_count":0,"repin_count":0,"is_private":0,"orig_source":"http://ww4.sinaimg.cn/bmiddle/7f404811jw1du5vv6dpnij.jpg","user":{"user_id":394332,"username":"Havetogo","urlname":"shouji132136652610","created_at":1338984624,"avatar":{"id":3061779,"farm":"farm1","bucket":"hbimg","key":"69d6d7842159946de9ca070c22da1714f259010afb4-WcVdOr","type":"image/jpeg","width":100,"height":100,"frames":1}},"board":{"board_id":1146189,"user_id":394332,"title":"创新的力量","description":"","category_id":null,"seq":6,"pin_count":1,"follow_count":0,"created_at":1340276719,"updated_at":1340276725,"is_private":0}},{"pin_id":8447272,"user_id":444560,"board_id":1146190,"file_id":2064511,"file":{"farm":"farm1","bucket":"hbimg","key":"aa4fab086fe5887299cf17df48a250f9df25e375c95b-M4izBs","type":"image/jpeg","width":440,"height":566,"frames":1},"media_type":0,"source":"weibo.com","link":"http://weibo.com/2596178104/ycTQfusRg","raw_text":"紫罗兰的致色原因:#翡翠知识普及#(61) 一般认为由于原生翡翠矿中含有微量的锰元素所致,由于锰元素的多寡和其他微量元素如铁等的渗入程度不同,其紫色也有浓淡深浅的剃度不同,如粉紫,茄紫,篮紫多种紫罗兰.十春九木,由于翡翠矿石含有锰是一种概率事件,所以紫色翡翠相对数量是很少的,再加上种水好则更少.","text_meta":{"tags":

Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Fix event ID 55, 50, 98, 140 disk error in event viewer Fix event ID 55, 50, 98, 140 disk error in event viewer Mar 19, 2024 am 09:43 AM

If you find event ID 55, 50, 140 or 98 in the Event Viewer of Windows 11/10, or encounter an error that the disk file system structure is damaged and cannot be used, please follow the guide below to resolve the issue. What does Event 55, File system structure on disk corrupted and unusable mean? At session 55, the file system structure on the Ntfs disk is corrupted and unusable. Please run the chkMSK utility on the volume. When NTFS is unable to write data to the transaction log, an error with event ID 55 is triggered, which will cause NTFS to fail to complete the operation unable to write the transaction data. This error usually occurs when the file system is corrupted, possibly due to the presence of bad sectors on the disk or the file system's inadequacy of the disk subsystem.

This Apple ID is not yet in use in the iTunes Store: Fix This Apple ID is not yet in use in the iTunes Store: Fix Jun 10, 2024 pm 05:42 PM

When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

How to realize the mutual conversion between CURL and python requests in python How to realize the mutual conversion between CURL and python requests in python May 03, 2023 pm 12:49 PM

Both curl and Pythonrequests are powerful tools for sending HTTP requests. While curl is a command-line tool that allows you to send requests directly from the terminal, Python's requests library provides a more programmatic way to send requests from Python code. The basic syntax for converting curl to Pythonrequestscurl command is as follows: curl[OPTIONS]URL When converting curl command to Python request, we need to convert the options and URL into Python code. Here is an example curlPOST command: curl-XPOST https://example.com/api

Tutorial on updating curl version under Linux! Tutorial on updating curl version under Linux! Mar 07, 2024 am 08:30 AM

To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

From start to finish: How to use php extension cURL to make HTTP requests From start to finish: How to use php extension cURL to make HTTP requests Jul 29, 2023 pm 05:07 PM

From start to finish: How to use php extension cURL for HTTP requests Introduction: In web development, it is often necessary to communicate with third-party APIs or other remote servers. Using cURL to make HTTP requests is a common and powerful way. This article will introduce how to use PHP to extend cURL to perform HTTP requests, and provide some practical code examples. 1. Preparation First, make sure that php has the cURL extension installed. You can execute php-m|grepcurl on the command line to check

Where can I find Alibaba ID? Where can I find Alibaba ID? Mar 08, 2024 pm 09:49 PM

In Alibaba software, once you successfully register an account, the system will assign you a unique ID, which will serve as your identity on the platform. But for many users, they want to query their ID, but don't know how to do it. Then the editor of this website will bring you detailed introduction to the strategy steps below. I hope it can help you! Where can I find the answer to Alibaba ID: [Alibaba]-[My]. 1. First open the Alibaba software. After entering the homepage, we need to click [My] in the lower right corner; 2. Then after coming to the My page, we can see [id] at the top of the page; Alibaba Is the ID the same as Taobao? Alibaba ID and Taobao ID are different, but the two

PHP8.1 released: Introducing curl for concurrent processing of multiple requests PHP8.1 released: Introducing curl for concurrent processing of multiple requests Jul 08, 2023 pm 09:13 PM

PHP8.1 released: Introducing curl for concurrent processing of multiple requests. Recently, PHP officially released the latest version of PHP8.1, which introduced an important feature: curl for concurrent processing of multiple requests. This new feature provides developers with a more efficient and flexible way to handle multiple HTTP requests, greatly improving performance and user experience. In previous versions, handling multiple requests often required creating multiple curl resources and using loops to send and receive data respectively. Although this method can achieve the purpose

Event ID 4660: Object deleted [Fix] Event ID 4660: Object deleted [Fix] Jul 03, 2023 am 08:13 AM

Some of our readers encountered event ID4660. They're often not sure what to do, so we explain it in this guide. Event ID 4660 is usually logged when an object is deleted, so we will also explore some practical ways to fix it on your computer. What is event ID4660? Event ID 4660 is related to objects in Active Directory and will be triggered by any of the following factors: Object Deletion – A security event with Event ID 4660 is logged whenever an object is deleted from Active Directory. Manual changes – Event ID 4660 may be generated when a user or administrator manually changes the permissions of an object. This can happen when changing permission settings, modifying access levels, or adding or removing people or groups

See all articles