I'm newbie with python and just stuck with my code. Basically I need check Norwegian VATs, in this case I'm using http://w2.brreg.no/enhet/sok/detalj.jsp?orgnr= website, . When I put in VatNo correct one I get:
f = re.findall("Du har oppgitt et ugyldig organisasjonsnummer",page)[0]
IndexError: list index out of range
But if I put incorrect VAT then working well..
This is how my code looks like:
import requests
import re
VatNo = '997814169' #ValidVat
def VatChecker():
page = requests.get("http://w2.brreg.no/enhet/sok/detalj.jsp?orgnr="+VatNo).text
x = "Du har oppgitt et ugyldig organisasjonsnummer"
f = re.findall("Du har oppgitt et ugyldig organisasjonsnummer",page)[0]
if f==x:
print ("Invalid VAT")
else:
print ("Valid VAT")
VatChecker()
Have you got any ideas where the problem is?
re.findall("Du har oppgitt et ugyldig organisasjonsnummer",page)returned empty list.re.findallbefore trying to index into it. If it's an empty list, then of course trying to reference the first element will produce an error.