Last active
October 6, 2019 19:48
-
-
Save qi-qi/8bfa5494153196bb30d3b481910a6a3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Colab Notebook: https://colab.research.google.com/drive/1bzT9XYTymi5E-x4C_-tmpla9_Ha2PgQd | |
import requests | |
from bs4 import BeautifulSoup | |
from datetime import datetime | |
keyword = 'ipad pro' #@param {type:"string"} | |
query = '+'.join(keyword.split(' ')) | |
dt_fmt = '%Y-%m-%d %H:%M:%S' | |
max_days_from_now = 15 #@param {type:"number"} | |
r = requests.get('https://www.blocket.se/stockholm?q=%s' % query) | |
soup = BeautifulSoup(r.content.strip(), 'html.parser') if r.status_code == 200 else None | |
for s in soup.findAll("article", class_="media item_row ptm pbm nmt"): | |
now = datetime.now() | |
dt = datetime.strptime(s.div.header.time.attrs['datetime'], dt_fmt) | |
if (now - dt).days <= max_days_from_now and keyword.lower() in s.div.h1.text.lower(): | |
link = s.a.attrs['href'] | |
location = s.div.header.div.text | |
title = s.div.h1.text | |
price = s.div.p.text.replace(" ", "") | |
print('=== %s ===\n%s\n%s\n%s\n%s\n' % (title, price, location, dt, link)) | |
#################### Result Sample ##################### | |
# === IPad Pro 12.9 tum 128GB Wi-Fi + 4G === | |
# 6500kr | |
# Datorer & TV-spel, Katarina, Sofia | |
# 2019-10-06 17:39:49 | |
# https://www.blocket.se/stockholm/IPad_Pro_12_9_tum_128GB_Wi_Fi___4G_87635362.htm?ca=11&w=1 | |
# | |
# === IPad Pro 12.9 128gb wi-fi 4G === | |
# 5999kr | |
# Datorer & TV-spel, Östermalm, Djurgården | |
# 2019-10-06 07:25:16 | |
# https://www.blocket.se/stockholm/IPad_Pro_12_9_128gb_wi_fi_4G_87621406.htm?ca=11&w=1 | |
# | |
# === IPad pro 9,7 128GB wifi + 4G === | |
# 5000kr | |
# Datorer & TV-spel, Huddinge | |
# 2019-10-05 22:12:26 | |
# https://www.blocket.se/stockholm/IPad_pro_9_7_128GB_wifi___4G_87359287.htm?ca=11&w=1 | |
# | |
# === Ipad Pro 10,5" 64GB + tillbehör === | |
# 6500kr | |
# Datorer & TV-spel, Vasastan, Norrmalm | |
# 2019-10-05 18:29:59 | |
# https://www.blocket.se/stockholm/Ipad_Pro_10_5__64GB___tillbehor_87617493.htm?ca=11&w=1 | |
# | |
# === IPad Pro 11" 4G 64GB + Pencil + Keyboard === | |
# 10500kr | |
# Datorer & TV-spel, Solna | |
# 2019-10-04 18:19:52 | |
# https://www.blocket.se/stockholm/IPad_Pro_11__4G_64GB___Pencil___Keyboard_87599412.htm?ca=11&w=1 | |
# | |
# === IPad Pro 12.9 256 gb och 64 gb 4G === | |
# 7600kr | |
# Datorer & TV-spel, Järfälla | |
# 2019-10-03 10:05:35 | |
# https://www.blocket.se/stockholm/IPad_Pro_12_9_256_gb_och_64_gb_4G_87223082.htm?ca=11&w=1 | |
# | |
# === Apple iPad Pro 3rd gen12.9 64GB Cellular === | |
# 11000kr | |
# Datorer & TV-spel, Sigtuna | |
# 2019-10-03 09:48:58 | |
# https://www.blocket.se/stockholm/Apple_iPad_Pro_3rd_gen12_9_64GB_Cellular_87573017.htm?ca=11&w=1 | |
# | |
# === IPad Pro 12,9 , 128gb , 4G === | |
# 6500kr | |
# Datorer & TV-spel, Sollentuna | |
# 2019-10-02 15:10:36 | |
# https://www.blocket.se/stockholm/IPad_Pro_12_9___128gb___4G_87563111.htm?ca=11&w=1 | |
# | |
# === IPad Pro 256 GB. 12.9 tum === | |
# 7500kr | |
# Datorer & TV-spel, Kungsholmen | |
# 2019-10-02 12:27:33 | |
# https://www.blocket.se/stockholm/IPad_Pro_256_GB__12_9_tum_87559857.htm?ca=11&w=1 | |
# | |
# === IPad Pro 12,9" 64 GB Cellular Space Grey === | |
# 13800kr | |
# Datorer & TV-spel, Katarina, Sofia | |
# 2019-10-01 17:01:51 | |
# https://www.blocket.se/stockholm/IPad_Pro_12_9__64_GB_Cellular_Space_Grey_87382959.htm?ca=11&w=1 | |
# | |
# === IPad Pro 11" 1TB Wi-Fi + 4G === | |
# 13999kr | |
# Datorer & TV-spel, Norrtälje | |
# 2019-09-30 17:31:08 | |
# https://www.blocket.se/stockholm/IPad_Pro_11__1TB_Wi_Fi___4G_87402611.htm?ca=11&w=1 | |
# | |
# === IPad Pro 10,5 wi-fi + cellular === | |
# 5600kr | |
# Datorer & TV-spel, Huddinge | |
# 2019-09-29 08:39:10 | |
# https://www.blocket.se/stockholm/IPad_Pro_10_5_wi_fi___cellular_87501543.htm?ca=11&w=1 | |
# | |
# === IPad Pro 9.7 32GB Rose Gold, Apple Pencil === | |
# 4500kr | |
# Datorer & TV-spel, Upplands Väsby | |
# 2019-09-28 18:11:08 | |
# https://www.blocket.se/stockholm/IPad_Pro_9_7_32GB_Rose_Gold__Apple_Pencil_87496701.htm?ca=11&w=1 | |
# | |
# === NYA IPAD PRO 12.9 tum Wifi med Garanti === | |
# 8490kr | |
# ButikDatorer & TV-spel, Katarina, Sofia | |
# 2019-09-28 07:16:56 | |
# https://www.blocket.se/stockholm/NYA_IPAD_PRO_12_9_tum_Wifi_med_Garanti_77388449.htm?ca=11&w=1 | |
# | |
# === Ipad pro 12.9 128gb === | |
# 5199kr | |
# Datorer & TV-spel, Hägersten, Liljeholmen | |
# 2019-09-26 12:33:23 | |
# https://www.blocket.se/stockholm/Ipad_pro_12_9_128gb_87456082.htm?ca=11&w=1 | |
# | |
# === Apple iPad Pro 11" 256Gb minne + wifi === | |
# 8500kr | |
# Datorer & TV-spel, Enskede, Årsta, Skarpnäck | |
# 2019-09-25 18:43:51 | |
# https://www.blocket.se/stockholm/Apple_iPad_Pro_11__256Gb_minne___wifi_87446936.htm?ca=11&w=1 | |
# | |
# === IPad Pro 12.9" 64GB (Penna + läderfodral) === | |
# 8000kr | |
# Datorer & TV-spel, Östermalm, Djurgården | |
# 2019-09-25 18:43:19 | |
# https://www.blocket.se/stockholm/IPad_Pro_12_9__64GB__Penna___laderfodral__87446927.htm?ca=11&w=1 | |
# | |
# === IPad Pro 12.9 32 gb WiFi === | |
# 5500kr | |
# Datorer & TV-spel, Södertälje | |
# 2019-09-23 14:56:14 | |
# https://www.blocket.se/stockholm/IPad_Pro_12_9_32_gb_WiFi_87409558.htm?ca=11&w=1# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment