How to implement page turning in python crawler
Jun 28, 2019 pm 04:32 PMMany friends who are new to python crawlers will encounter the problem of page turning in python crawlers. I will introduce one here.
The website that needs to be crawled is as shown in the picture
There are four pages of this plant queried. When we usually turn pages, our first thought is to click on the next page on the page. The same is true when writing a crawler. We want to extract links on the page for access. But doing so is cumbersome and inefficient.
There are generally two ways to turn pages:
1. Observe the link changes when the website turns pages
2. If the request method of writing a crawler is a post request, then It is necessary to observe whether the changes in post data are regular.
Today I will talk about the first method
As shown in the picture, when I click on the next page, I observe the link change in the address bar
We can be surprised to find that there is a page keyword in the link, and it happens to be 2. Let’s test it and change the value of page in the link to 3, and find that the access is normal. It's exactly the third page. Therefore, we found a way to turn the page and change the value of the keyword in the link.
So the steps of the page turning process are:
1. Get the total number of web pages
2. Use the for loop to change the value of page to turn the page.
The specific page turning code is implemented as follows:
Get the total page number
Network request method
Change the page value in the request header
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to implement page turning in python crawler. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How Do I Use Beautiful Soup to Parse HTML?

How to Use Python to Find the Zipf Distribution of a Text File

How to Work With PDF Documents Using Python

How to Cache Using Redis in Django Applications

How to Perform Deep Learning with TensorFlow or PyTorch?

Introducing the Natural Language Toolkit (NLTK)
