Python XML parsing Baidu sticky rice information

Source: Internet
Author: User

First use of the crawler Baidu glutinous rice provided by the API to capture the day of Beijing's group purchase information, save as Numi.html

Import Xml.etree.ElementTree as ET
Import OS

Class Nuomi ():

def __init__ (self):

Self.numi=[]
def Parse (Self,filepath):

Tree=et.parse (filepath)
Root =tree.getroot ()
For URL in root.iter (' URL '):
nuomi_lei={}
Data=url.find (' data ')
If data is not None:
Display=data.find (' Display ')
If display is not None:
Try
nuomi_lei[' title ']=display.find (' title '). Text
Except Exception as E:
Print ("No title")
Try
nuomi_lei[' Businesstitle ']=display.find (' Businesstitle '). Text
Except Exception as E:
Print ("No businesstitle")
Try
nuomi_lei[' value '] =display.find (' value '). Text
Except Exception as E:
Print ("No value")
Try
nuomi_lei[' Price ']=float (display.find (' price '). Text)
Except Exception as E:
Print ("No pire")
Self.numi.append (Nuomi_lei)
Return (Self.numi)


if __name__ = = ' __main__ ':

Nuomi=nuomi ()
Date=nuomi. Parse (' numi.html ')
Print (len (date))

Python XML parsing Baidu sticky rice information

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.