-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfire_poo.py
73 lines (53 loc) · 2.75 KB
/
fire_poo.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env python
#!/usr/bin/env python
from xml.dom.minidom import parse
import xml.dom.minidom
from BeautifulSoup import BeautifulStoneSoup, SoupStrainer
import urllib2
import re
def printResults(results):
addons = 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)
myDoc = parse (urllib2.urlopen('https://addons.allizom.org/en-us/firefox/api/1.5/search/firebug'))
myResults = myDoc.getElementsByTagName("searchresults")[0]
#print "****Get type***"
#print myResults.getElementsByTagName("addon")
#Get all the addon elements in the library
#addons = myResults.getElementsByTagName("addon")
#Print each addon's title and name(s)
#printResults(myResults)
#############################BEAUTIFUL SOUP####################################
xml_soup = BeautifulStoneSoup(urllib2.urlopen('https://addons.allizom.org/en-us/firefox/api/1.5/search/fire'))
#print xml_soup.addon
addon_id = xml_soup.addon["id"]
addon_name = xml_soup.addon.nameTag.string
addon_type = xml_soup.addon.type.string
addon_type_num = xml_soup.addon.type["id"]
addon_version = xml_soup.addon.version.string
print 'Name is: ' + addon_name + '\tID is: ' + addon_id + '\tType is: ' + addon_type + "\tType Number is: " + addon_type_num
print 'Version is:' + addon_version
all_addons = xml_soup.searchresults
#print "Number in all_addons:\t" + str(len(xml_soup.findAll('addon')))
#print xml_soup.findAll(lambda tag: tag.nameTag.string == "Firebug")
#print xml_soup.find(text="FireGestures")
#print xml_soup.find(text='FireGestures').parent.parent #gets complete xml for addon "FireGestures"
#print xml_soup.find(text='FireGestures').findNext() #gets extenstion tag for FireGestures
#string below gets the id into a string based on the addon name.
numeric_id_tuple = xml_soup.find(text='FireGestures').findParent().findParent().attrs[0] #"get id for addon name"
numeric_id = str( numeric_id_tuple[1] ) #numeric_id is now a string
#print xml_soup.findAll(id=numeric_id) #prints just the Firegestures xml
#firegestures_xml = xml_soup.findAll(id=numeric_id)
firegestures_xml = xml_soup.find(text='Firefox 3 theme for Firefox 4').findParent().findParent()
print firegestures_xml.version.string
try:
print xml_soup.find(text='Firepug').findParent().findParent()
except AttributeError:
print ('The addon is not in the results')
#Here is the code for getting an addon's id field.
#def get_addon_id(self, addon_name):
#numeric_id = self.parsed_xml.find(text=addon_name).findParent().findParent().attrs[0] #"get id for addon name"
#return numeric_id[1]