Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import re
- URL = 'http://www.catalog.update.microsoft.com/ScopedViewInline.aspx?updateid='
- UPDATES = {}
- def gen(updateid):
- if updateid not in UPDATES:
- kb = KB(updateid)
- kb.get_updates()
- tmp = {updateid: kb}
- UPDATES.update(tmp)
- for updateid in kb.replaced_to:
- new_kb = KB(updateid)
- print('{} replaced to {}'.format(kb, new_kb))
- gen(new_kb.updateid)
- class KB:
- def __init__(self, updateid):
- r = requests.get(URL + updateid)
- soup = BeautifulSoup(r.text, 'html.parser')
- self.description = soup.find('div', {'id': 'titleDiv'}).find('span', {'id': 'ScopedViewHandler_titleText'}).text
- self.name = re.findall(r'KB\d+', self.description)[-1]
- self.url = URL + updateid
- self.updateid = updateid
- self.replaced_to = []
- def get_updates(self):
- l = []
- r = requests.get(self.url)
- soup = BeautifulSoup(r.text, 'html.parser')
- for a in soup.find('div', {'id': 'supersededbyInfo'}).find_all('a'):
- l.append(re.findall(r'[\d,\w,\-]+$', a['href'])[-1])
- self.replaced_to = l
- if len(l) == 0:
- self.not_replaced = True
- else:
- self.not_replaced = False
- def __str__(self):
- return self.name
- # Обновление для системы безопасности Windows Server 2012 R2 (KB3067505)
- # https://www.catalog.update.microsoft.com/ScopedViewInline.aspx?updateid=33cd6b5a-f5a8-4d2d-b163-96e155eed7b9
- updateid = '33cd6b5a-f5a8-4d2d-b163-96e155eed7b9'
- gen(updateid)
- print('\n\nNot replaced updates:')
- for kb in UPDATES:
- if UPDATES[kb].not_replaced == True:
- print('{}: {}'.format(UPDATES[kb].name, UPDATES[kb].description))
- print('URL: {}\n'.format(UPDATES[kb].url))
Advertisement
Add Comment
Please, Sign In to add comment