python: อ่านเนื้อความจากเว็บ
Submitted by wd on Wed, 2007-01-31 09:48
เราสามารถใช้ python อ่านเนื้อหาจากเว็บได้โดยใช้โมดุล urllib
เอาตัวอย่างจาก Dive into Python - 11.2. How not to fetch data over HTTP
>>> import urllib
>>> data = urllib.urlopen('http://diveintomark.org/xml/atom.xml').read() 1
>>> print data
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="0.3"
xmlns="http://purl.org/atom/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xml:lang="en">
<title mode="escaped">dive into mark</title>
<link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
<-- rest of feed omitted for brevity -->ด้วยวิธีนี้เราสามารถนำเข้าไฟล์สตรีมทั้งหลายได้โดยสะดวก
- Printer-friendly version
- Log in or register to post comments
- 3977 reads







Recent comments