I am trying to build a small scraper for a danish page containing information about foundations. The aim is to sort them for relevance for me, rather than going through them by hand.
I used a browser to locate the post request to the API, which is: https://api.legatbogen.dk/api/search/advanced
and the request is: {"fetchSize":30,"orderBy":4,"skip":0,"subcategories":[8]}
, which returns the json that I want to use.
However, when I try to use the API through Python:
import requests
response = requests.get(
"https://api.legatbogen.dk/api/search/advanced",
params = {"fetchSize":30,"orderBy":4,"skip":0,"subcategories":[8]},
headers= {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
}
)
I get '<html><body><h2>404 Not found</h2></body></html>'
instead of the json file.
To reproduce
CodePudding user response:
- Use
requests.post
method - Use
json=
parameter instead ofparams=
import json
url = "https://api.legatbogen.dk/api/search/advanced"
payload = {"fetchSize": 30, "orderBy": 4, "skip": 0, "subcategories": [8]}
data = requests.post(url, json=payload).json()
print(json.dumps(data, indent=4))
Prints:
{
"totalResults": 1595,
"results": [
{
"foundationName": "Liljekonvalfonden",
"foundationNamedId": "liljekonvalfonden-kge",
"grantId": 12466,
"grantName": "Yngre gartnere under 30 \u00e5r til uddannelse og rejser",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": 12,
"month": 10,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Liljekonvalfonden",
"foundationNamedId": "liljekonvalfonden-kge",
"grantId": 12467,
"grantName": "Uddannelse/studielegater for sang- og musiktalenter inden for klassisk musik i K\u00f8ge-omr\u00e5det",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": 12,
"month": 10,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Give Borger- og Erhvervsforenings Jubil\u00e6umsfond",
"foundationNamedId": "give-borger--og-erhvervsforenings-jubilumsfond",
"grantId": 12512,
"grantName": "Studerende p\u00e5 videreg\u00e5ende uddannelse inden for handel og h\u00e5ndv\u00e6rk ",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": 29,
"month": 9,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Hesteafgiftsfonden",
"foundationNamedId": "hesteafgiftsfonden",
"grantId": 12537,
"grantName": "Hesteholdets udviklingsmuligheder gennem tilskud til projekter",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": 25,
"month": 9,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Maskiningeni\u00f8rernes Initiativfond",
"foundationNamedId": "maskiningenirernes-initiativfond",
"grantId": 12659,
"grantName": "Bem\u00e6rkelsesv\u00e6rdige eksamensprojekter fra Danmarks ingeni\u00f8rskoler",
"totalDonationSize": 10000,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Nibe Skoles Jubil\u00e6ums- og Afholdslegat",
"foundationNamedId": "nibe-skoles-jubilums-og-afholds--legat",
"grantId": 18314,
"grantName": "Form\u00e5l ifm. Nibe Skole, opmuntringer til elever/l\u00e6rere/andre skoleform\u00e5l",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "K\u00f8benhavns Guldsmedelaugs Legatfond",
"foundationNamedId": "kjbenhavns-guldsmedelaugs-legatfond",
"grantId": 20957,
"grantName": "Projekter indenfor eller med tilknytning til guldsmedebranchen",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": 30,
"month": 9,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "N\u00e6stved Handelsstandsforening Jubil\u00e6umsfond",
"foundationNamedId": "nstved-handelsstandsforening-jubilumsfond",
"grantId": 17758,
"grantName": "Tr\u00e6ngende enker efter medlemmer af N\u00e6stved Handelstandsforening m.m.",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Ingeni\u00f8rforeningen i Danmarks Elektrofond",
"foundationNamedId": "ingenirforening-i-danmark-elektrofond",
"grantId": 18464,
"grantName": "Ingeni\u00f8rkandidater inden for det elektrotekniske/elektroniske fagomr\u00e5de v. E-kandidatprisen",
"totalDonationSize": 1070000,
"deadline": {
"dayInMonth": 7,
"month": 10,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Ingeni\u00f8rforeningen i Danmarks Elektrofond",
"foundationNamedId": "ingenirforening-i-danmark-elektrofond",
"grantId": 18465,
"grantName": "Indsatser inden for det elektrotekniske/elektroniske fagomr\u00e5de v. Elektroprisen",
"totalDonationSize": 1070000,
"deadline": {
"dayInMonth": 7,
"month": 10,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Fabrikant Chas. Otzens Fond",
"foundationNamedId": "fabrikant-chas--otzens-fond",
"grantId": 17398,
"grantName": "Unges uddannelse, sport, fritid, syge mennesker m.m.",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 2
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "ESL Elevfond",
"foundationNamedId": "elevfond---esl",
"grantId": 18460,
"grantName": "Boligorganisationer, som indg\u00e5r en uddannelsesaftale med en ungdomselev under 25 \u00e5r",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Promilleafgiftsfonden for frugtavlen og gartneribruget",
"foundationNamedId": "promilleafgiftsfonden-for-frugtavlen-og-gartneribruget",
"grantId": 18252,
"grantName": "Frugt- og gartneribrugets udviklingsmuligheder og konkurrenceevne",
"totalDonationSize": 7200000,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Kompetencefond - ESL",
"foundationNamedId": "kompetencefond---esl",
"grantId": 18516,
"grantName": "Ejendomsfunktion\u00e6rernes efteruddannelse hos Almene Boliger",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Frederiksborg Gymnasiums For\u00e6ldrefond",
"foundationNamedId": "frederiksborg-gymnasiums-forldre-fond",
"grantId": 12955,
"grantName": "Rentefri l\u00e5n til betaling af fx studierejser p\u00e5 Frederiksborg Gymnasium",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 2
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Johs Hansens Jubil\u00e6umslegat",
"foundationNamedId": "johs-hansens-jubilumslegat",
"grantId": 12820,
"grantName": "Dimittender fra Viborg Handelsskole ",
"totalDonationSize": 3000,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Horsens Folkeblads Fond",
"foundationNamedId": "horsens-folkeblads-fond",
"grantId": 13308,
"grantName": "Udgivelser samt kulturelle, presse- og uddannelsesform\u00e5l i Horsens-egnen",
"totalDonationSize": 100000,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Mors\u00f8 Landbrugsskoles Fond",
"foundationNamedId": "mors-landbrugsskoles-fond",
"grantId": 14121,
"grantName": "Unges uddannelse, aktiviteter m.m. i relation til Mors\u00f8 Lanbrugsskole",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": 31,
"month": 5,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "HT's Medarbejderfond",
"foundationNamedId": "hts-effektiviseringsfond",
"grantId": 15537,
"grantName": "Anstatte i MOVIAs uddannelse, rekreationsophold og fritidsaktiviteter",
"totalDonationSize": 650000,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Polyteknisk forenings studenter sociale Fond",
"foundationNamedId": "polyteknisk-forenings-studenter-sociale-fond",
"grantId": 15851,
"grantName": "Arrangementer eller l\u00f8bende aktiviteter med studentersocialt sigte",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "\u00d8stsj\u00e6llands Andelsvaskeris Fond",
"foundationNamedId": "stsjllands-andelsvaskeris-fond",
"grantId": 14630,
"grantName": "Kulturelle, almennyttige og almenvelg\u00f8rende form\u00e5l i Stevns/Faxe/Vall\u00f8 kommuner",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": 16,
"month": 4,
"periodType": 1
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Entrepern\u00f8rforeningens Underst\u00f8ttelsesfond",
"foundationNamedId": "entreprenrforeningens-understttelsesfond",
"grantId": 13480,
"grantName": "Underst\u00f8ttelse til tidligere medlemmere af entrepen\u00f8rforeningen m.m.",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Etatsr\u00e5d Just Christian Haurowitz og hustru Bodil Johanne, f\u00f8dt Therkelsens Legat til bedste for Horsens by",
"foundationNamedId": "etatsrd-just-chr-haurowitz-og-hustru-b-j-fdt-therkelsens-legat-til-bedste-f-horsens-by",
"grantId": 13769,
"grantName": "Unge under uddannelse og v\u00e6rdigt tr\u00e6ngende i Horsens kommune",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Menighedsfakultetet ",
"foundationNamedId": "menighedsfakultetet",
"grantId": 15941,
"grantName": "Studerende og deres uddannelsesforl\u00f8b hos Menighedsfakultetet",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "H\u00e6rens Linieofficerskorps Jubil\u00e6umsfond",
"foundationNamedId": "hrens-linieofficerskorps-jubilumsfond--h-o-k-human-resources-afdelingen-hr22",
"grantId": 13774,
"grantName": "Officerer i h\u00e6ren for fortjenstfuldt virke/mod milit\u00e6re studier",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Kirsten og Freddy Johansens Fond",
"foundationNamedId": "kirsten-og-freddy-johansens-fond",
"grantId": 13840,
"grantName": "Almennyttige form\u00e5l; h\u00e5ndv\u00e6rk, kultur, kunst, forskning mv.",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Haandv\u00e6rkersparekassens Fond",
"foundationNamedId": "haandvrkersparekassens-fond",
"grantId": 13983,
"grantName": "Unge under uddannelse m.fl. i Haandv\u00e6rkersparekassens virkeomr\u00e5de",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Frederiksberg Kommunale Sygeplejerskeforenings Legat",
"foundationNamedId": "frederiksberg-kommunale-sygepleje-erskeforenings-legat",
"grantId": 17623,
"grantName": "Ferie/rekreation/hj\u00e6lp/studier til sygeplejersker, Frederiksberg Kommune",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "A/S Den Danske Margarinefabriks Jubil\u00e6umsfond af 7 maj 1925 og 1940",
"foundationNamedId": "as-den-danske-margarinefabriks-jubilumsfond-af-7-maj-1925-og-1940",
"grantId": 15498,
"grantName": "Tidligere funktion\u00e6rer ved Den Danske Margarinefabrik, samt tr\u00e6ngende",
"totalDonationSize": 16000,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
},
{
"foundationName": "Dansk Industris og H\u00e5ndv\u00e6rks Medaljefond i \u00c5rhus Amt",
"foundationNamedId": "dansk-industris-og-hndvrks-medaljefond-i-rhus-amt",
"grantId": 18287,
"grantName": "L\u00e6rlinge, der har udm\u00e6rket sig fagligt & socialt p\u00e5 deres arbejdsplads",
"totalDonationSize": 0,
"deadline": {
"dayInMonth": null,
"month": null,
"periodType": 8
},
"openForApplications": true,
"grantMaking": true
}
]
}