Home > OS >  setting a parsed vuln to null if it cant be parsed
setting a parsed vuln to null if it cant be parsed

Time:09-15

I have some logic that attempts to parse a field out of a webpage.

    thesev=cve.find("span", class_="label-warning").text   #should assume null if DoE

however, sometime this value isnt always available to be parsed.

How can i set it to null (None) ?

Thanks

CodePudding user response:

Without knowing which package you're working with or what errors you're getting or what the rest of your script looks like, you could just use a ternary operator when assigning the value to thesev:

thesev = cve.find("span", class_="label-warning").text or None

This will evaluate if cve.find() has returned something and if not, then it reverts to whatever value you put after the or. Note: if this returns a blank string, python may see that as a value and return it instead of None. Again, seeing the rest of your code/the errors and/or outputs you're getting would help.

  • Related