123456789101112131415161718192021222324252627 |
- import codecs
- from bs4 import BeautifulSoup
- # Reading the data inside the xml file to a variable under the name data
- with codecs.open('c:/tmp/sitemap.xml', 'r','utf-8') as f:
- data = f.read()
- # Passing the stored data inside the beautifulsoup parser
- bs_data = BeautifulSoup(data, 'xml')
- # Finding all instances of tag
- b_unique = bs_data.find_all('url')
- cnt=0
- for el in b_unique:
- loc=el.find('loc')
- print(loc.text)
- #b_name = bs_data.find('child', {'name':'Acer'})
- #print(b_unique)
- # Using find() to extract attributes of the first instance of the tag
- #b_name = bs_data.find('child', {'name':'Acer'})
- #print(b_name)
- # Extracting the data stored in a specific attribute of the `child` tag
- #value = b_name.get('qty')
- #print(value)
|