Created
July 6, 2022 10:43
-
-
Save thestuntcoder/4c480a42915ae5671a72247e8d031d5a to your computer and use it in GitHub Desktop.
Find Norwegian company IDs by company name (simple example)
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
# -*- coding: utf-8 -*- | |
import sys | |
import urllib3 | |
from bs4 import BeautifulSoup | |
# Examples how to run this script: | |
# python3 company_no.py jumpking | |
# python3 company_no.py coca_cola | |
def main(): | |
mylink = "https://w2.brreg.no/enhet/sok/treffliste.jsp;?navn=" + sys.argv[1] + "&orgform=0&fylke=0&kommune=0" | |
http = urllib3.PoolManager() | |
resp = http.request("GET", mylink) | |
soup = BeautifulSoup(resp.data, "html.parser") | |
for liste in soup.find("div", {"id": "pagecontent"}).find_all("div", {"class": "liste"}): | |
if liste.find("a"): | |
if "detalj" in liste.find("a")["href"]: | |
print("Company id: " + liste.find("a")["href"][17:]) | |
if __name__ == '__main__': | |
status = main() | |
sys.exit(status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment