Skip to content

Commit

Permalink
cd
Browse files Browse the repository at this point in the history
Signed-off-by: BJ <q378648220@163.com>
  • Loading branch information
BingJiang authored and GofunTR committed Apr 13, 2019
1 parent b594736 commit aa8f03e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -9,3 +9,4 @@ lxml==3.4.4
cssselect==0.9.1
beautifulsoup4==4.6.0
requests==2.18.4
pytz==2017.3
18 changes: 18 additions & 0 deletions scraper.py
Expand Up @@ -22,3 +22,21 @@
# All that matters is that your final data is written to an SQLite database
# called "data.sqlite" in the current working directory which has at least a table
# called "data".
import requests
from bs4 import BeautifulSoup
import scraperwiki
from datetime import datetime
import pytz
req = requests.get('http://www.shunon.com.hk/pricing.php')
soup = BeautifulSoup(req.content, 'html.parser')
table = soup.find_all('table', {'class': 'Font16Boldc'})[1]
element = table.find_all('p')[0]
text = element.text.split()
titles = [text[i] for i in (0, 2, 4, 6)]
values = [int(text[i].replace('$', '').replace(',', ''))
for i in (1, 3, 5, 7)]
hkt = pytz.timezone('Asia/Hong_Kong')
dt = datetime.now().replace(tzinfo=hkt).date()
data = {titles[i]: values[i] for i in range(0, 4)}
data['date'] = dt
scraperwiki.sqlite.save(unique_keys=['date'], data=data)

0 comments on commit aa8f03e

Please sign in to comment.