Web crawler study(1)

1. setup the python3 enviromemt via download the excuted files from the website https://www.python.org/downloads/

2.Atfer seting up ,confirm that whether the enviroment is successful or not .

   open the CMD windows  /  Linux terminal  to type "python" ,then press the enter  key.

3.create a python file for coding.eg :demo.py

  # coding=gbk                                      #it can be avoid the syntaxerror:non-utf-8 code starting with x3
  

      import urllib.request                             # urllib.request  is a package which usally used to get the infomation form the web pages
   
  url="http://www.baidu.com"                  # the web site that we want to get the information from it

  response=urllib.request.urlopen(url)      # get the reponse from the web server,the expected result is the information  that we wanted.
 
  html=response.read()                          # return the information the Binary string,so that the infromation can be displayed.
 
  codeOfHtml=html.decode('utf-8')          #decoding the information
 
  print(codeOfHtml)                                #print the information

4. Run the demo.py script

原文地址:https://www.cnblogs.com/yongdaiblog-201409/p/6731056.html