I've managed to get my script to print out a line of text based on what is in the line:
if "cvename" in line:
CVE = list_of_line[4:5]
print "The CVE number is ", ' '.join(CVE)
print " "
CVEfile.write("CVE-" + str(CVE) + '\n')
which prints out:
['http://cve.mitre.org/cgi-bin/cvename.cgi?name=1999-0016][Xref']
But what I want is just the value '1999-0016'
I'm assuming a regular expression can be used to do this but I don't have much experience in using them. What I've noticed is that the value I want to extract always starts with a year as it is a CVE number
Always try to use a more specific approach before using regular expressions. You need to parse an url? Use urlparse.
import urlparse
u = 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=1999-0016'
q = urlparse.urlparse(u).query
values = urlparse.parse_qs(q).get('name')
if values is not None:
print values[0]
# prints '1999-0016'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With