Advertisement
Guest User

sdfsf

a guest
Feb 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. ua = UserAgent()
  2. user_agent = {'User-agent': ua.random} #changement d'user-agent (random)
  3. url = "https://www.leboncoin.fr/locations/offres/ile_de_france/hauts_de_seine/?th=" + page + "&mre=" + prix_max + "&sqe=" + surface + "&ret=2&furn=" + m
  4. req = requests.get(url, headers=user_agent)
  5. stat = req.status_code
  6. if stat == 200:
  7. if "Urgentes" not in req.text:
  8. print "URL not found"
  9. break
  10. else:
  11. print "\033[42m URL found \033[0m"
  12. print "*" * 15
  13. if "Aucune" in req.text: #si aucune annonce trouver
  14. print "Aucune annonce trouve"
  15. print "*" * 15
  16. break
  17. else:
  18. soup = BeautifulSoup(req.text,"html.parser")
  19. resultats = soup.find('section', {"class":"tabsContent block-white dontSwitch"})
  20. annonces = resultats.find_all("li")
  21. for annonce in annonces:
  22. tag_a = annonce.find("a")
  23. lien_annonce = tag_a.get("href")
  24. title = annonce.find("h2").text.strip()
  25. price = annonce.find("h3").find(text=True, recursive=False).strip()
  26. dte = annonce.find('p', {'itemprop':'availabilityStarts'}).get('content')
  27. # FILTRE ICI
  28. print('titre:%s' % title)
  29. print('price:%s' % price)
  30. print('date:%s' %dte)
  31. print('lien:%s' % lien_annonce)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement