Created
July 23, 2020 18:38
-
-
Save nonnullish/0b0f95735ecd03be30873788792e7617 to your computer and use it in GitHub Desktop.
get the data of a company from its vat identification number (polish NIP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
from bs4 import BeautifulSoup | |
import re | |
if len(sys.argv) == 1: | |
sys.exit() | |
nip = sys.argv[1] | |
# quick, before they find out that i am in fact a robot | |
data = { | |
'q': nip, | |
'szukaj': 'Szukaj' | |
} | |
url = 'http://bnip.pl/' | |
response = requests.post(url, data=data) | |
response.encoding = 'ISO-8859-2' | |
doc = BeautifulSoup(response.text, 'html.parser') | |
for element in doc.find_all('a'): | |
element.decompose() | |
row_tags = doc.find_all('tr') | |
for row in row_tags: | |
row = row.text.strip() | |
row = re.sub(r"\s+", " ", row) | |
print (row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment