The definition and URL structure of a python crawler without basic writing.

Source: Internet
Author: User
Tags file url

The definition and URL structure of a python crawler without basic writing.

1. Definition of Web Crawler

Web crawlers, that is, Web Spider, are an image name.
Comparing the Internet to a Spider, a Spider is a web crawler.
Web crawlers search for Web pages based on their link addresses.
Read the content of a webpage from a page (usually the homepage) of a website and find other links on the webpage,
Search for the next Webpage through these links until all the webpages of the website are crawled.
If the whole Internet is regarded as a website, the web spider can use this principle to capture all the web pages on the Internet.
In this case, web crawler is a crawling program and a crawling program.
The basic operation of Web Crawlers is to capture webpages.
So how can we get the page we want as we like?
Start with the URL.

Ii. Webpage Browsing Process

In fact, the process of capturing a webpage is the same as that of browsing a webpage through the IE browser.
For example, enter www.baidu.com in the address bar of your browser.
The process of opening a webpage is actually that the browser acts as a browser "client" and sends a request to the server, "grabbing" the server file, and then explaining and presenting it.
HTML is a markup language that uses tags to tag content and parse and distinguish it.
The function of the browser is to parse the obtained HTML code, and then convert the original code into a website page that we can directly see.

3. Concepts and examples of URI and URL

Simply put, the URL is the http://www.baidu.com string entered on the browser side.
Before you understand a URL, you must first understand the concept of URI.
What is URI?
Each type of available resources on the Web, such as HTML documents, images, video clips, and programs, are located by a Universal Resource Identifier (URI.
A URI consists of three parts:
① Resource Access naming mechanism;
② Host name for storing resources;
③ The Name Of The resource, represented by the path.
The URI is as follows:
Http://www.why.com.cn/myhtml/html1223/
We can explain it as follows:
① This is a resource that can be accessed through the HTTP protocol,
② It is located on the host www.webmonkey.com.cn,
③ Access through the path "/html/html40.

Iv. URL comprehension and Examples

A URL is a subset of a URI. It is the abbreviation of Uniform Resource Locator ".
Generally speaking, URLs are strings used to describe information resources on the Internet and are mainly used in various WWW client programs and server programs.
URL can be used to describe various information resources in a unified format, including files, server addresses and directories.
The URL format is ([] with square brackets ):
Protocol: // hostname [: port]/path/[; parameters] [? Query] # fragment

The URL format consists of three parts:
① The first part is the protocol (or service mode ).
② The second part is the Host IP address (sometimes including the port number) that contains the resource ).
③ The third part is the specific address of the host resource, such as the Directory and file name.
The first part and the second part are separated by the ": //" symbol,
The second part and the third part are separated by the "/" symbol.
The first part and the second part are indispensable, and the third part can be omitted sometimes.

5. simple comparison between URL and URI

URI is a lower-level URL abstraction, a string text standard.
In other words, URI belongs to the parent class, and URL belongs to the URI subclass. A URL is a subset of a URI.
URI is defined as a uniform resource identifier;
The URL is defined as a uniform resource identifier.
The difference between the two is that URI represents the path of the Request server and defines such a resource.
The URL also describes how to access this resource (http ://).

The following is a small example of two URLs.

1. Example of http url:
The super text transmission protocol HTTP is used to provide resources for the Super Text Information Service.
Example: http://www.peopledaily.com.cn/channel/welcome.htm
Its computer domain name is www.peopledaily.com.cn.
The super Startup File (.html) is welcome.htm under the directory/channel.
This is a computer of the People's Daily of China.
Example: http://www.rol.cn.net/talk/talk1.htm
The computer domain name is www.rol.cn.net.
The super Startup File (.html) is the talk1.htm under the directory/talk.
This is the address of the reide chat room. You can enter room 1st of the reide chat room.

2. File URL
When a file is expressed as a URL, the server uses file to indicate the Host IP address, file access path (directory), and file name.
Sometimes the Directory and file name can be omitted, but the "/" symbol cannot be omitted.
Example: file: // ftp.yoyodyne.com/pub/files/foobar.txt
The above URL indicates a file in the pub/files/directory of the ftp.yoyodyne.com host. The file name is foobar.txt.
Example: file: // ftp.yoyodyne.com/pub
Indicates the directory/pub on the ftp.yodyne.com host.
Example: file: // ftp.yoyodyne.com/
Represents the root directory of the ftp.yoyodyne.com host.

The most important processing object of a crawler is the URL. It obtains the required file content based on the URL and further processes it.
Therefore, an accurate understanding of URLs is essential to understanding web crawlers.

Now, we will introduce the basic knowledge here. Next we will perform some actual crawler operations.


How familiar can python be to write crawler code?

You are familiar with crawlers. I have written it in java before, and I will learn python later. I will be able to write the Python version after reading the api in two days.

If you do not know the crawler principle at all, it will be slow. If you do not have any other programming language experience, it will be even slower.

How can I write a crawler in python? Can I give an example of using python to write a crawler? Everybody

Regular Expression matching analysis Web pages, wget catch things, the simplest should be this idea. This stuff can't be done in a book.

Related Article

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.