我正在编写一个脚本来从ubuntu网站
获取所有软件包版本以下是我在代码中使用的示例网址
https://lists.ubuntu.com/archives/ubuntu-security-announce/2018-April/004359.html
这是我的代码
#!/usr/bin/python
import re,sys,shutil,requests,bs4
def main():
a = []
b = []
c = []
url = raw_input("Please enter url\n")
res = requests.get(url)
soup = bs4.BeautifulSoup(res.text, 'html.parser')
test = soup.find('pre')
test_text = str(test.text.encode('ascii','replace')).replace("?"," ")
result = test_text[test_text.find("package versions:"):test_text.find("References:")]
versions=re.findall(r'Ubuntu.*', result)
for i in range(len(versions)):
if (i+1 < len(versions)):
a.append(re.sub(' +', ' ',test_text[test_text.find(versions[i]):test_text.find(versions[i+1])]))
else:
a.append(re.sub(' +', ' ',test_text[test_text.find(versions[len(versions)-1]):test_text.find("References:")]))
print a
if __name__ == "__main__":
main()
我希望以某种方式输出,即如果有多个软件包版本具有相同的软件包,则可以使用它们进行分组,并且它应该存储在Ubuntu OS版本的单独集合中,即Ubuntu 17.10或Ubuntu 16.04 LTS或Ubuntu 14.04 LTS,具体取决于关于咨询内容
例如,我需要以下格式输出:
Ubuntu 14.04 LTS:
(libruby1.9.1|ruby1.9.1|ruby1.9.3) => 1.9.3.484-2ubuntu1.11
(libruby2.0|ruby2.0) => 2.0.0.484-1ubuntu2.9
我当前的输出
[
'Ubuntu 17.10:\n libruby2.3 2.3.3-1ubuntu1.5\n ruby2.3 2.3.3-1ubuntu1.5\n\n',
'Ubuntu 16.04 LTS:\n libruby2.3 2.3.1-2~16.04.9\n ruby2.3 2.3.1-2~16.04.9\n\n',
'Ubuntu 14.04 LTS:\n libruby1.9.1 1.9.3.484-2ubuntu1.11\n libruby2.0 2.0.0.484-1ubuntu2.9\n ruby1.9.1 1.9.3.484-2ubuntu1.11\n ruby1.9.3 1.9.3.484-2ubuntu1.11\n ruby2.0 2.0.0.484-1ubuntu2.9\n\nIn general, a standard system update will make all the necessary\nchanges.\n\n'
]