Skip to main content

An interface for fetching statistical data from BRÅ. This is not an official service!

Project description

# BRÅ Scraper

This is a Python module for fetching statistical data about reported crime from [Brottsförbyggande rådet](http://statistik.bra.se/solwebb/action/index).

### Installation

`pip install -r requirements.txt`


### Usage

Init scraper:

```python
from bra_scraper.BRA import BRA
scraper = BRA()
```

List topics.

```python
print scraper.topics
```

Explore a topic.

```python

# Get a topic by name (or url)
topic = scraper.topic(u"Månads- och kvartalsvis - Land och län 1975-2014, land och region 2015-")

# Get available regions
print topic.regions

# Get available crimes
print topic.crimes

```

Make query.

```python
# Query date range
data = topic.query(period_start="2016-01-01", period_end="2016-06-30")

# Query by region and crimes
data = topic.query(regions=["Bjuv kommun"], crimes=[u"Våldsbrott"])

```

Save results.

```python
data.to_csv("my_data_dump.csv")
```

### Command line usage

With `run.py` you can run the scraper from the command line. Run `python run.py --help` for help:

```
-t TOPIC, --topic TOPIC
name of the topic to be scraped (from http://statistik
.bra.se/solwebb/action/start?menykatalogid=1)
-o OUTFILE, --outfile OUTFILE
store result in this file
-ps PERIOD_START, --period_start PERIOD_START
start date (for example 2016-09-01)
-pe PERIOD_END, --period_end PERIOD_END
end date (for example 2016-09-01)
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bra_scraper-0.1.6.tar.gz (12.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page