Advertisement
Embry0

Untitled

Feb 3rd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import offer as offer
  2. import requests
  3. from bs4 import BeautifulSoup
  4. from sys import exit
  5. import re
  6.  
  7.  
  8. url = 'https://www.olx.bg/ads/user/lpAO/'
  9. page = requests.get(url)
  10. # print(page.text)
  11.  
  12. if not page.status_code == 200:
  13.     exit()
  14.  
  15. html_soup = BeautifulSoup(page.content, "html.parser")
  16. # print(html_soup.prettify())
  17.  
  18. all_user_info = html_soup.find('div', id='listContainer')
  19. # print(all_user_info)
  20. user_name = all_user_info.find('h3', class_='xxx-large')
  21. # print(user_name)
  22. all_user_offers = html_soup.find_all(class_='listHandler')
  23. # print(len(all_user_offers))    # колко обяви има
  24.  
  25. for offer in all_user_offers:
  26.     offer_title = offer.find_all('a', class_='marginright5 link linkWithHash detailsLink')
  27.     offer_price = offer.find_all('p', class_='price')
  28.     offer_img = offer.find_all('img', class_='fleft')
  29.     if None in (offer_title, offer_price, offer_img):
  30.         continue
  31.  
  32.     print(offer_title)
  33.     print(offer_price)
  34.     print(offer_img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement