Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #-*- coding: utf-8 -*-
- import requests
- import sys
- import time
- from bs4 import BeautifulSoup
- from fake_useragent import UserAgent
- from datetime import date
- """
- https://www.leboncoin.fr/locations/offres/ile_de_france/hauts_de_seine/?th=1&mre=600&sqe=1&ret=2&furn=1
- sqe=1 = 20m2
- """
- def pag():
- for y in soup.find_all('section', {"class":"tabsContent block-white dontSwitch"}):
- urls = y.find("li")
- ok = urls.find("a", {"class":"list_item clearfix trackable"})
- for x in ok.text:
- print x.get("href")# petit bug d'url a regler
- today = date.today()
- a_h = today.day - 2 #avant hier
- a_ah = today.day - 3# avant avant hier
- #Villes :
- ville = [
- u"Sèvre",
- u"Boulogne-Billancourt",
- u"Issy-les-Moulineaux",
- u"Saint-Cloud",
- u"Meudon",
- u"Ville-d'Avray",
- u"Clamart",
- u"Puteaux",
- u"Nanterre"
- ]
- #les dernieres annonces sur 3 jours
- date_post = [
- "Aujourd'hui",
- "Hier",
- str(a_h),
- str(a_ah)
- ]
- prix_max = "600"
- surface = "1" #surface max : 1 = 20m2 ; 2 = 25m2; 3 = 30m2; 4 = 35m2; 5 = 40m2; 6 = 50m2.....
- m = "1" #1 = meublé; 2 = non meublé
- page = "1"
- res = 0
- while 1:
- ua = UserAgent()
- user_agent = {'User-agent': ua.random} #changement d'user-agent (random)
- url = "https://www.leboncoin.fr/locations/offres/ile_de_france/hauts_de_seine/?th=" + page + "&mre=" + prix_max + "&sqe=" + surface + "&ret=2&furn=" + m
- req = requests.get(url, headers=user_agent)
- stat = req.status_code
- if stat == 200:
- if "Urgentes" not in req.text:
- print "URL not found"
- break
- else:
- print "\033[42m URL found \033[0m"
- print "*" * 15
- if "Aucune" in req.text: #si aucune annonce trouver
- print "Aucune annonce trouve"
- print "*" * 15
- break
- else:
- soup = BeautifulSoup(req.text,"html.parser")
- for p in soup.find_all('section', {"class":"item_infos"}):
- title = p.find("h2")
- price = p.find("h3")
- for i in ville:
- for d in date_post:
- if d in p.text:
- if i in p.text:
- t = title.text.replace(" ","").replace("\n","")
- print "\033[32m[+] \033[0m " + t.replace(" ","") + " : \033[41m" + price.text.replace(" ","").replace(" ","").replace("\n","") + "\033[0m / " + i + " | date : "+ d + "/" + str(today.month)
- # affiche du titre de l'annonce, du prix, de la ville et de la date
- print "\033[34m-\033[0m" * 30 + "\n"
- pag()
- res = res + 1
- else:
- break
- print "*" * 15
- print "resultat : " + str(res) #nombre de resultat trouver
- time.sleep(1800)# min / temps avec renvoi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement