Guest User

Untitled

a guest
Oct 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #!/usr/bin/python3
  2. '''
  3. CARBON SCRAPER v0.1
  4. '''
  5. from bs4 import BeautifulSoup
  6. import requests
  7.  
  8. # This function creats a list of pages of items
  9. def pcs_list():
  10. global url
  11. url = "https://www.avito.ma/fr/pres-t%C3%A9touan/ordinateurs_portables/lenovo_x1--%C3%A0_vendre?mpr=5000"
  12. r = requests.get(url)
  13. souped = BeautifulSoup(r.content,'lxml')
  14.  
  15.  
  16.  
  17. links = []
  18. for item in souped.find_all('h2', {'class': 'fs14'}):
  19. links.append(item.a.get("href"))
  20. title = item.get_text()
  21. if "lenovo" in str(title):
  22.  
  23. for link in links:
  24. r1 = requests.get(link)
  25. souped1 = BeautifulSoup(r1.content, 'lxml')
  26. for code in souped1.find_all('h2',{'class':"price-header fs18"}):
  27. price = str(code.get_text())
  28. for code in souped1.find_all('div', {'class': 'span10'}):
  29. description = str((code.get_text()))
  30.  
  31. print(title)
  32. print("Link of item = "+ link)
  33. print("price :"+ price)
  34. print("description : " + description)
  35. else :
  36. print("No results was found ")
  37.  
  38. pcs_list()
  39.  
  40. item = pcs_list()
  41.  
  42. import smtplib
  43. from email.mime.multipart import MIMEMultipart
  44. from email.mime.text import MIMEText
  45.  
  46. gmailUser = 'user@gmail.com'
  47. gmailPassword = 'pwd'
  48. recipient = 'recipient@gmail.com'
  49. message = item
  50.  
  51. msg = MIMEMultipart()
  52. msg['From'] = gmailUser
  53. msg['To'] = recipient
  54. msg['Subject'] = "Resultados"
  55. msg.attach(MIMEText(message))
  56.  
  57. mailServer = smtplib.SMTP('smtp.gmail.com', 587)
  58. mailServer.ehlo()
  59. mailServer.starttls()
  60. mailServer.ehlo()
  61. mailServer.login(gmailUser, gmailPassword)
  62. mailServer.sendmail(gmailUser, recipient, msg.as_string())
  63. mailServer.close()
Add Comment
Please, Sign In to add comment