Bonjour à tous
Etant nouveau, je ne sais pas si je dois poster ce qui suit ici, sinon n'hésitez pas à me dire où ^^
Alors, le code ci-dessous permet de scrapper une page sur Ebay concernant les nouvelles annonces et plus (200 articles). J'ai mis en plus un filtre [Keywords] qui me permet de filtrer uniquement ce que je recherche soit environ 7 articles sur 200, jusqu'ici tout fonctionne.
Par contre une fois le mail envoyé je reçois uniquement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 from bs4 import BeautifulSoup import requests import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import time import random #Paramètre_############################################################################# url ='https://www.ebay.fr/sch/267/i.html?_from=R40&_nkw=star+wars&_sop=10&_ipg=200' keywords = ['INTEGRALE', 'Thrawn', 'Legacy'] email_address = 'YourGmailAccount@gmail.com' recipient_address = 'MyRecipent@email.com' subject_desc = 'Tile of the Email' password = 'YourPWD' ####################################################################################### #Collecte de données sur Ebay def get_data(url): r = requests.get(url) soup = BeautifulSoup(r.text, 'html.parser') return soup def parse(soup): data = [] results = soup.find_all('div', {'class' : 's-item__info clearfix'}) for item in results: try: title = item.find('h3', {'class': 's-item__title'}).text.replace('Nouvelle annonce','') Price = item.find('span', {'class':'s-item__price'}).text Link = item.find('a', {'class' : 's-item__link'})['href'] products = {'Title' : title, 'Price' : Price, 'Link' : Link} data.append(products) except: continue return data soup = get_data(url) book_titles = parse(soup) #Données filtrées provenant de parse(soup) en utilisant "keywords" qui sont dans les paramètres def filter(book_titles): for title in book_titles: for key, value in title.items(): if key == 'Title': for books in keywords: if books in value: for email in str(title).splitlines(): return(email) subj = filter(book_titles) #Envoi par email des données filtrées def create_message(from_address, to_address, subject, message): try: msg = MIMEMultipart() msg.attach(MIMEText(message)) msg['From'] = from_address msg['To'] = to_address msg.passowrd = password msg['Subject'] = subject pass except: wait = random.uniform(0, 2*60) localtime = time.localtime() result = time.strftime("%I:%M:%S %p", localtime) print('ReTracking it is', result) time.sleep(wait) return msg if __name__ == '__main__': msg = create_message( from_address=email_address, to_address=recipient_address, subject=subject_desc, message=subj ) server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login("YourGmailAccount@gmail.com", msg.passowrd) print("login success") server.send_message(msg) print("This message has been sent") server.quit()
Alors que je suis censé recevoir :
Code : Sélectionner tout - Visualiser dans une fenêtre à part {'Title': 'Star Wars - Legacy Saison II T01: Terreur sur Carreras EO NEUF SOUS BLISTER', 'Price': '35,00 EUR', 'Link': 'https://www.ebay.fr/itm/304223244315?hash=item46d51e501b:g:tqIAAOSwjhZgOq-I'}
J'avoue être coincé sur cette partie. auriez-vous une idée de ce qu'il manque ? (ou mal fait haha)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 {'Title': 'Star Wars - Legacy Saison II T01: Terreur sur Carreras EO NEUF SOUS BLISTER', 'Price': '35,00 EUR', 'Link': 'https://www.ebay.fr/itm/304223244315?hash=item46d51e501b:g:tqIAAOSwjhZgOq-I'} {'Title': 'LOT Star Wars Legacy 1 2 3 DELCOURT TBE', 'Price': '19,99 EUR', 'Link': 'https://www.ebay.fr/itm/313750655371?hash=item490cff118b:g:T0gAAOSwLXxhjsGY'} {'Title': 'Star Wars: Legacy of the Force: Bloodlines, Karen Traviss, Used; Good Book', 'Price': '8,30 EUR', 'Link': 'https://www.ebay.fr/itm/384496532637?hash=item5985c77c9d:g:D3cAAOSwlOxhjqgg'} {'Title': 'Star Wars: Legacy of the Force IX - Invincible, Denning, Troy, Used; Very Good B', 'Price': '15,42 EUR', 'Link': 'https://www.ebay.fr/itm/384496531150?hash=item5985c776ce:g:fswAAOSwBblhjqgQ'} {'Title': "STAR WARS LES OMBRES DE L'EMPIRE INTEGRALE 2 EVOLUTION EN TTBE COMICS TRES RARE", 'Price': '45,00 EUR', 'Link': 'https://www.ebay.fr/itm/363619642859?hash=item54a96b6deb:g:AEoAAOSw3flhgCJR'} {'Title': 'Star Wars Thrawn - Allianzen (Die Thrawn-Trilogie (K... | Livre | état très bon', 'Price': '12,69 EUR', 'Link': 'https://www.ebay.fr/itm/125000062368?hash=item1d1a9595a0:g:o38AAOSwsW1hjpoA'} {'Title': 'BD Comics Star Wars Legacy 6 - VI. Renégat', 'Price': '30,00 EUR', 'Link': 'https://www.ebay.fr/itm/275024537109?hash=item4008bd6615:g:p44AAOSwSzJhjjNX'}
En vous remerciant![]()
Partager