Sunday, 10 April 2022

Failed to parse application numbers from a map using requests

I'm trying to scrape information from a map using requests module. The information I'm after are in several box like containers, which pops up when the yellow colored area on the map is clicked. I wish to parse the application number from each of the boxes.

I tried to observe network activity in dev tools to find out any such link which contains the required information but I failed.

The following is how I've created the script but I ended up getting different information when I execute it:

import json
import requests
from pprint import pprint

link = 'https://gisportal.campbellriver.ca/arcgis/rest/services/DevelApps_MuniBdry_Parcels/FeatureServer/1/query'

params = {
    'f': 'json',
    'returnGeometry': 'true',
    'spatialRel': 'esriSpatialRelIntersects',
    'geometry': '{"xmin":-13971465.778085683,"ymin":6418264.391068123,"xmax":-13932330.019603727,"ymax":6457400.14955008,"spatialReference":{"wkid":102100}}',
    'geometryType': 'esriGeometryEnvelope',
    'inSR': '102100',
    'outFields': '*',
    'outSR': '102100',
    'resultType': 'tile',
    'quantizationParameters': '{"mode":"view","originPosition":"upperLeft","tolerance":76.43702828507084,"extent":{"xmin":-13970672.893748092,"ymin":6429207.023229747,"xmax":-13936535.293969424,"ymax":6466884.27089714,"spatialReference":{"wkid":102100,"latestWkid":3857}}}'
}
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36',
}

with requests.Session() as s:
    s.headers.update(headers)
    res = s.get(link,params=params)
    for item in res.json()['features']:
        pprint(item['attributes'])

Current output (truncated):

'APPROX_HA': 17.68241328,
 'BCAssessVa': 111000,
 'COMPLETED': 'y',
 'DESCRIPTIO': 'Rural Two',
 'ELECTORAL': 'JUR336',
 'HOUSE': 0,
 'HTTP': 'http://GIS01/ParcelTifs/NoPlan.pdf',
 'HTTP1': 'http://webmap.campbellriver.ca/ZoningPdf/RU-2.pdf',
 'JUROLL': '0336029068.076',
 'LAST_UPDAT': 'JUL 15 2004',
 'LEGAL': 'SECTION 14  TOWNSHIP 2  COMOX LAND DISTRICT  PLAN VIP552A W 1/2 OF '
          'SE 1/4, MANAGED FOREST 0068.',
 'LINK_ID': 12399,
 'LOT': ' ',
 'LOT_DESC': 'ACRES',
 'LOT_SIZE': '80',
 'LTO_NUMBER': 'CA7321763'

Expected output:

Status                Received
Application number    P1800100
Type                  Official Community Plan Bylaw Amendment (OCP)

How can I scrape Application Numbers from this map using requests?



from Failed to parse application numbers from a map using requests

No comments:

Post a Comment