Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import gzip
- import re
- import sched, time
- s = sched.scheduler(time.time, time.sleep)
- oldAnnonces = []
- def checkAnnonces(sc):
- print(" Checking new annonces...")
- opener = urllib.request.build_opener()
- opener.addheaders = [('Host','www.leboncoin.fr'),
- ('Connection',' keep-alive'),
- ('Cache-Control',' max-age=0'),
- ('Upgrade-Insecure-Requests',' 1'),
- ('User-Agent',' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'),
- ('Accept',' text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'),
- ('Accept-Encoding',' gzip, deflate, br'),
- ('Accept-Language',' fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7')
- ]
- urllib.request.install_opener(opener)
- response = urllib.request.urlopen("https://www.leboncoin.fr/recherche/?category=10®ions=18&cities=Nantes_44300&price=200-600&square=20-max");
- gzipFile = gzip.GzipFile(fileobj=response)
- html = gzipFile.read().decode('utf-8');
- newAnnonces = re.findall( r'{"list_id":([^{]*)', html, re.M|re.I)
- for annonce in newAnnonces:
- if annonce not in oldAnnonces:
- print("FOUND a new annonce ! \n"+annonce)
- oldAnnonces.append(annonce)
- urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?user=39030424&pass=nfODujINlvTlsD&msg=Nouvelle%20Annonce").read();
- s.enter(60, 1, checkAnnonces, (sc,))
- opener = urllib.request.build_opener()
- opener.addheaders = [('Host','www.leboncoin.fr'),
- ('Connection',' keep-alive'),
- ('Cache-Control',' max-age=0'),
- ('Upgrade-Insecure-Requests',' 1'),
- ('User-Agent',' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'),
- ('Accept',' text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'),
- ('Accept-Encoding',' gzip, deflate, br'),
- ('Accept-Language',' fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7')
- ]
- urllib.request.install_opener(opener)
- response = urllib.request.urlopen("https://www.leboncoin.fr/recherche/?category=10®ions=18&cities=Nantes_44300&price=200-600&square=20-max");
- gzipFile = gzip.GzipFile(fileobj=response)
- html = gzipFile.read().decode('utf-8');
- oldAnnonces = re.findall( r'{"list_id":([^{]*)', html, re.M|re.I)
- urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?user=39030424&pass=nfODujINlvTlsD&msg=Nouvelle%20Annonce").read();
- print(" Added old annonces");
- s.enter(60, 1, checkAnnonces, (s,))
- s.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement