Webscraping AirBnB using Raspberry Pi, Python and Beautiful Soup

preview_player
Показать описание
I use my Pi Zero to automate an AirBnB search that I sometimes do.
I get bored of clicking lots of buttons and dates and filters so thought I'd use Beautiful Soup to automate it.

Next: I'll automate it sending me an email, mid-week.
I will ad some code so that it searches with checkin date of the closest Friday/Saturday date to the current date.

As you may have noticed I've set it to include "hot tub" in the filter.
By modifying the filter and observing the way the subsequent URL changes you can adapt the code to suit your particular requirements. Eg if you need a hairdryer, or a helicopter landing pad, or whatever the f you want!

Check out the Minimalist online python IDE :

Рекомендации по теме
Комментарии
Автор

New pi user here and new to python programming (and programming in general) so I really appreciate the video. 👍

mxcollin
Автор

Would be a better video if you just used normal voices. 👍

mxcollin
Автор

!! In the video I had the dates in the wrong format - now corrected and working, eg: : checkin = '2019-12-30'
checkout = '2019-12-31'

python
Автор

Better code : I have used the class_ attribute in beautiful soup to only pick out the hyperlinks for the found properties, and omit the other hrefs.


#!/usr/bin/python3
from bs4 import BeautifulSoup
import urllib.request

county = 'South-West-England--UK'
checkin = '2019-12-30'
checkout = '2019-12-31'
adults =


request = urllib.request.Request(url)
response =

soup = BeautifulSoup(response.read(), features="html.parser")

print ("County : " + county)
print ("Checkin : " + checkin)
print ("Checkout : " + checkout)

list2 = soup.findAll('div', attrs={'class': "_1ebt2xej"})
for i in list2:
print(i.text)

for url in soup.findAll('a', class_ ="_i24ijs"):

python
Автор

Code here :
(Run as Python3)



#!/usr/bin/python3
from bs4 import BeautifulSoup
import urllib.request

county = 'South-West-England--UK'
checkin = '2019-12-30'
checkout = '2019-12-31'
adults =


request = urllib.request.Request(url)
response =

soup = BeautifulSoup(response.read(), features="html.parser")

print ("County : " + county)
print ("Checkin : " + checkin)
print ("Checkout : " + checkout)

list2 = soup.findAll('div', attrs={'class': "_1ebt2xej"})
for i in list2:
print(i.text)

for a in soup.findAll('a', href=True):

python
Автор

Even Better Code Still! :


This saves output as formatted html with links to search results.
Nice use of the "Zip" function which helped a lot.


#!/usr/bin/python3
from bs4 import BeautifulSoup
import requests
import urllib.request
area = 'South-West-England--UK'
checkin = '2020-02-15'
checkout = '2020-02-16'
homes =
source =

result = requests.get(url)
src = result.content
soup = BeautifulSoup(src, features="html.parser")

loc = ("Area : " + area)
cin = (" Checkin : " + checkin)
cout = (" Checkout : " + checkout)
search = loc + cin + cout

list2 = soup.findAll('div', attrs={'class': "_1ebt2xej"})
tags = soup.find_all('a', class_="_i24ijs")

html = "<html>\n<head>\n<style>p {margin: 0!important }</style>\n<body>"+ search + "\n"

for i, j in zip(tags, list2):
a = j.text # description
b = i.text # a href
print (a +" " + b + c + "\n")

html += '\n<p>' + 'url:' + '<a href=' + c +'</a>'+a+'</p>\n'

with open('htub.html', 'w+') as file:

file.write(html + "</body></html>")
file.close()
i = 1
for link in list2:
print(str(i) +" "+ link.text)
i = i + 1

python
join shbcf.ru