Skip to content

Commit

Permalink
Renamed notebook and wrote small working example (#2)
Browse files Browse the repository at this point in the history
* Added sections with description
* Removed output of cells
  • Loading branch information
wagnerpeer authored and jrebstadt committed Jan 22, 2019
1 parent b4c419e commit af684a9
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 286 deletions.
151 changes: 151 additions & 0 deletions exploring.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Park-Vorhersage"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Website to extract info from"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"url = r'https://www.parken-osnabrueck.de/'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Selenium\n",
"\n",
"Use selenium to drive headless firefox (other browsers can be configured, too)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"from selenium import webdriver\n",
"from selenium.webdriver.firefox.options import Options"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"options = Options()\n",
"options.headless = True\n",
"driver = webdriver.Firefox(options=options)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## robots.txt\n",
"\n",
"Check if crawling is generally not desired by website operator"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"from urllib import robotparser"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parser = robotparser.RobotFileParser(url=url)\n",
"parser.read()\n",
"'Website can be parsed: {}'.format(parser.can_fetch('*', url))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read page source and extract information"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"driver.get(url)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use BeautifulSoup to easily read page source"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"from bs4 import BeautifulSoup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"soup = BeautifulSoup(driver.page_source)\n",
"\n",
"for item in soup.find_all('span', 'parking-ramp-utilization'):\n",
" print(item.text)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit af684a9

Please sign in to comment.