-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxml_firebug.py
48 lines (41 loc) · 1.56 KB
/
xml_firebug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env python
#!/usr/bin/env python
from xml.dom.minidom import parse
import xml.dom.minidom
import urllib
def printResults(results):
addon = myResults.getElementsByTagName("addon")
for addon in addons:
print ("***Addon***")
print ("Name: %s" % addon.getElementsByTagName("name")[0].childNodes[0].data)
for author in addon.getElementsByTagName("author"):
print ("Author Name: %s" % author.getElementsByTagName("name")[0].childNodes[0].data)
#open an xml file and parse it into a dom
myDoc = parse (urllib.urlopen('https://addons.allizom.org/en-us/firefox/api/1.5/search/fire'))
myResults = myDoc.getElementsByTagName("searchresults")[0]
#Get all the addon elements in the library
addons = myResults.getElementsByTagName("addon")
#Print each addon's title and name(s)
printResults(myResults)
"""
#insert a new addon in the library
newaddon = myDoc.createElement("addon")
newaddonTitle = myDoc.createElement("title")
titleText = myDoc.createTextNode("Beginning Python")
newaddonTitle.appendChild(titleText)
newaddon.appendChild(newaddonTitle)
newaddonname = myDoc.createElement("name")
nameName = myDoc.createTextNode("PeterNorton, et al")
newaddonname.appendChild(nameName)
newaddon.appendChild(newaddonname)
myResults.appendChild(newaddon)
print("Added a new addon!")
printLibrary(myResults)
#Find ellison addon
for addon in myResults.getElementsByTagName("addon"):
for name in addon.getElementsByTagName("name"):
if name.childNodes[0].data.find("Ellison") != -1:
removedaddon = myResults.removeChild(addon)
removedaddon.unlink()
print ("Removed a addon.")
"""