Python provides an example of how to capture a web page to generate an Excel file,
This example describes how to capture a web page and generate an Excel file using Python. We will share this with you for your reference. The details are as follows:
Python mainly uses PyQuery to capture web pages. This is the same as jQuery's usage and is extremely powerful.
The sample code is as follows:
#-*-Encoding: UTF-8-*-import sysimport localeimport stringimport tracebackimport datetimeimport urllib2from pyquery import PyQuery as pq # determine the encodingreload (sys); sys. setdefaultencoding ('utf8'); f = open('gongsi.csv ', 'w'); for I in range (): d = pq (url = "http://www.yourwebname.com /? Code = HANGYELINGYU & myFlag = allShow & SiteID = 122 & PageIndex = % d "% (I); itemsa = d ('dl dt ') # title element itemsb = d ('dl dd') # title element for j in range (0, len (itemsa): f. write ("% s, \" % s \ "\ n" % (itemsa [j]. get ('title'), itemsb [j * 2]. text); # end for # end forf. close ();
Next, use notepad##to open gongsi.csv, convert it to the ANSI encoding format, and save it. Open the csv file in Excel and save it as an Excel file.