6.3小节完成。 · tinylambda/python3-cookbook@bb687b7 · GitHub
Skip to content

Commit bb687b7

Browse files
committed
6.3小节完成。
1 parent a889b1c commit bb687b7

4 files changed

Lines changed: 179 additions & 23 deletions

File tree

basic/datetime/basicdatetime.py

Lines changed: 24 additions & 0 deletions

basic/datetime/datetime.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

cookbook/c06/p03_simple_xml.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
Topic: 解析简单的XML
5+
Desc :
6+
"""
7+
from urllib.request import urlopen
8+
from xml.etree.ElementTree import parse
9+
10+
11+
def simple_xml():
12+
# Download the RSS feed and parse it
13+
u = urlopen('http://planet.python.org/rss20.xml')
14+
doc = parse(u)
15+
16+
# Extract and output tags of interest
17+
for item in doc.iterfind('channel/item'):
18+
title = item.findtext('title')
19+
date = item.findtext('pubDate')
20+
link = item.findtext('link')
21+
22+
print(title)
23+
print(date)
24+
print(link)
25+
print()
26+
27+
if __name__ == '__main__':
28+
simple_xml()
29+

source/c06/p03_parse_simple_xml_data.rst

Lines changed: 126 additions & 3 deletions

0 commit comments

Comments
 (0)