Home » Python » Python simple web crawler program

Python simple web crawler program

import urllib"
Import httplib2
Import urllib.request
Import WebBrowser
Url=' http://www.163.com'
Content=urllib.request.urlopen (URL).Read ()
Open (' 163.com.html' ' wb');.Write (content)
Webbrowser.open_new_tab (' 163.com.html')
Webbrowser.open_new_tab (' www.baidu.com')

 the above code used to grab NetEase on the first page of content, and to grasp the content stored in the name of 163.com.html HTML file, and then use the default browser to display the HTML file, 
< span style= "font-size:18px;" > finally use the default browser to open Baidu page.


The version of

Python is 3.2, and in Python2, only

is used when referencing Libraries


import urllib"
Import httplib2
Import webbrowser
without adding
import, urllib.request
", and ""



content=urllib.request.urlopen (URL).Read () 
should be written as" "



content=urllib.urlopen (URL),.Read (), 
open (' 163.com.html' ' wb');.Write (content) 
should be written as



open (' 163.com.html' ' w');.Write (content) 


Latest