明天参加考试,需要让我的program.py文件正常工作。我将通过GeoRSS提要https://www.tvfoodmaps.com/MVFN.xml解析具体并获取这些属性数据; "纬度","经度" ,"标题" ,"描述"编译成单独的列表。创建这些列表后,我需要编写以创建一个要在arcmap中保存这些点和数据的要素类。该脚本将在ArcMap中运行,以映射餐厅位置并包含信息。 现在,我一直坚持将所有数据都放到表格中。问题在于获取标题和描述部分,因为看起来如果我可以获得标题,那么它不会运行描述,反之亦然。任何帮助将非常感激!这是我到目前为止所拥有的;
import os, urllib
#store the pathname to where you want to add text file to
#path = arcpy.GetParameterAsText(0) # pathname to folder
#FullFCOutputPath = arcpy.GetParameterAsText(1)
path = "https://www.tvfoodmaps.com/MVFN.xml"
f = urllib.urlopen(path)
myfile = f.read()
lstFieldNames = [ "Latitude", "Longitude" , "Title" , "Description" ]
lstPoints = myfile.split('<georss:point>')
#print lstPoints[1]
Latitudes = []
Longitudes = []
for Gval in lstPoints:
if Gval.find('</georss:point>') <> -1:
LatPos1 = 0
LatPos2 = Gval.index(' ')
LonPos1 = Gval.index(' ') + 1
LonPos2 = Gval.index('</georss:point>')
Latitudes.append(Gval[LatPos1:LatPos2])
Longitudes.append(Gval[LonPos1:LonPos2])
lstTitles = myfile.split('<item>')
Titles = []
Descriptions = []
#print lstTitles[1]
for Tval in lstTitles:
if Tval.find('<item>') <> -1: #
TlePos1 = Tval.index('<title>') + 7
TlePos2 = Tval.index('</title>')
Title = (Tval[TlePos1:TlePos2])
Title = Title.replace(''',"'")
Titles.append(Title)
elif Tval.find('</description>') <> -1:
DesPos1 = Tval.index('<description>') + 13
DesPos2 = Tval.index('</description>')
Description = (Tval[DesPos1:DesPos2])
Description = Description.replace(''',"'")
Descriptions.append(Description)