Zhihu crawlers 3: Request analysis (a copy of the previously crawled data is provided) and crawlers are provided

Source: Internet
Author: User

Zhihu crawlers 3: Request analysis (a copy of the previously crawled data is provided) and crawlers are provided

This article is original by the blogger. For reposted, please indicate the source: my blog-zhihu crawler 3: Request Analysis

Git crawler Project address (Where are the followers and stars ~~) : Https://github.com/MatrixSeven/ZhihuSpider (finished)

Attach a copy of the previously crawled data (mysql): link:Https://github.com/MatrixSeven/ZhihuSpider/README. MD Download only, do not like, do not star, negative comment ~ Blue and thin mushrooms)

In the previous article, the Director mentioned the general idea of crawling crawlers: zhihu Crawler 2: crawler process design (with a database provided for crawling ), this article will study and analyze the simulated login knowledge.

Ps: A lot of data ~ Download only do not like, do not star, blue thin mushrooms

First of all, there are already a huge number of articles simulating login on the Internet, and simulating login is much easier than simulating login to Weibo Baidu. However, based on the principle of good start and end, let's repeat it to the end.

1. Tools

Well, what about tools? We can use the browsers we usually use. The shiny f12 is enough. Then we can use the Fiddler to check the login status...

2. login Analysis

Open the http://www.zhihu.com, click Login, and then directly F12, debug the developer tool, select NetWork, enter the account password and verification code, click Login, found the right side of the NetWork request.

An email request is found with the following request information:

Request address: https://www.zhihu.com/login/emailrequest method: Post

The following content does not care about it, but is directly pulled to the bottom:

.. The following information is found:

_xsrf:xxxxxxxxxxxxxxxxxxpassword:xxxxxcaptcha:HDMGemail:xxxxxx@xx.com

Well, it's Post. Check whether the login is successful and check the error message when the login fails.

Intentionally enter the wrong email address and password

The result is as follows:

1. the email address does not exist:

2. Incorrect password:

How is the login success status identified?

Here we use Fiddler

Open Fiddler, once again to know the login, and then find the https://www.zhihu.com/login/email request. found that the login successful return a Json string:

Well, there is another _ xsrf. Where is this parameter?

In fact, _ xsrf is basically stored in the source code of the page. Open the login page and right-click to view the source code. You can find that:

Haha, it turns out to be in a hidden domain ....

Haha, is this intentionally easy to crawl... the process is much simpler than I thought ..

But the specific line does not work. You can try the code again. Haha...

 

#3. Follow/follow Analysis

Open https://www.zhihu.com/people/sweets07/followers. then, start the analysis request at f12.

Directly scroll the page and an asynchronous request is found. The request address is:

https://www.zhihu.com/api/v4/members/Sweets07/followers?per_page=10&include=data%5B%2A%5D.employments%2Ccover_url%2Callow_message%2Canswer_count%2Carticles_count%2Cfavorite_count%2Cfollower_count%2Cgender%2Cis_followed%2Cmessage_thread_token%2Cis_following%2Cbadge%5B%3F%28type%3Dbest_answerer%29%5D.topics&limit=10&offset=30

The request parameters are as follows:

include:data[*].employments,cover_url,allow_message,answer_count,articles_count,favorite_count,follower_count,gender,is_followed,message_thread_token,is_following,badge[?(type=best_answerer)].topicslimit:10offset:30

The returned Json is:

Wow. There are various types of information...

For example:

1. The address of the next request

2. Personnel Information, id, profile picture, school, company, signature, number of followers .....

Well, it's enough for us to take part of it. Right, it's the ID... some IDS can directly open the personal page .. then there are some problems with this request, because an error occurs when the cookie get is directly carried:

{"Message": "unauthenticated identity", "code": 100, "name": "AuthenticationException "}

 

This is because an additional header is added during the request:

So where is this parameter ??

Find the parameter and find it in the cookie requesting personal homepage information.

Followers and followers are similar .....

 

Let's go here. Next, let's start coding...

// I love Java (QQ group): 170936712 (click to join)

Zhihu Crawler 2: crawler process design (with a database crawled out)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.