在Python中用xml.doc.minidom

2024-10-01 02:29:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从Zillow的API中得到房子的地块大小,但是我没有打印出正确的结果。你知道吗

我的目标是打印“lotSizeSqFt”的XML字段中的值。每当我打印时,我得到的都是空的方括号。有人知道发生了什么吗?你知道吗

from bs4 import BeautifulSoup
import requests
import urllib, urllib2
import csv

from xml.dom import minidom
import xml.dom.minidom

#makes an api call for a given address
def makeCall(address, cityStateZip):
    url = "http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=X1-ZWz1bah9j0jpqj_493z4&address=" + address + "&citystatezip=" + cityStateZip

    #parse the XML document
    xml = urllib2.urlopen(url)
    xmldoc = minidom.parse(xml)

    return xmldoc



def getData(address, cityStateZip):

    #returns parsed XML doc
    xmldoc = makeCall(address, cityStateZip)

    #get necesary data
    lotsize =  xmldoc.getElementsByTagName("lotSizeSqFt")

    return lotsize


address = "10608 Floral Park Lane"
cityStateZip = "North Potomac, MD 20878"

print getData(address, cityStateZip)

Tags: fromimporturlparseaddressdefxmlurllib2