Python Crawler Learning Note 1

Source: Internet
Author: User

Joined the lab, to write crawlers, previously written in Java, the newly learned Python practice practiced hand

The first is the awarding process, the framework is as follows:

The first is the post method, the code is as follows:

1 ImportUrllib2 ImportUrllib23Url='http://someserver.com/cgi-bin/register.cgi'4User_agent='mozilla/4.0'5values={6     'name':'liuyuqing',7     ' Location':'DUT',8     'language':'python'9 }Tenheaders={ One     'Cookies':'name=liuyuqing', A     'user-agent': User_agent - } -Data=Urllib.urlencode (values) thereq=Urllib2. Request (url,data,headers) -Response=Urllib2.urlopen (req) -The_page=response.read ()

If the request does not have a data parameter, the Get method is sent

Response.geturl () #获得真正的url

Response.info () #获得返回报文头

There are also some custom opener and handler knowledge for the moment, do not learn to start the regular expression ~

=================== Gorgeous split-line ===========================

The basic knowledge of regular expression is not a table, directly speaking Python application:

Import Rereg=re.compile (R'<title> (. *) </title>') List=  Re.findall (reg,text) for in list:    print  i      Pass

The most basic HelloWorld so much, the rest of tomorrow, sleep the zzz ...

Python Crawler Learning Note 1

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.