th0m45s5helby

Untitled

May 24th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. #### This program scrapes naukri.com's page and gives our result as a
  2. #### list of all the job_profiles which are currently present there.
  3.  
  4. import requests
  5. from bs4 import BeautifulSoup
  6. from selenium import webdriver
  7. from selenium.webdriver.common.keys import Keys
  8. from selenium.webdriver.chrome.service import Service
  9. from selenium.webdriver.chrome.options import Options
  10. import time
  11. import sys
  12. #sys.stdout=open('test.txt','w')
  13. url = "https://wazirx.com/exchange/BTC-INR"
  14. chrome_options=Options()
  15. chrome_options.add_argument("--headless")
  16. chrome_options.add_argument("--no-sandbox")
  17. chrome_options.add_argument("window-size=1400,2100")
  18.    
  19. driver = webdriver.Chrome(executable_path='./chromedriver',options=chrome_options)
  20. driver.get(url)
  21.  
  22. time.sleep(15)
  23.  
  24. html = driver.page_source
  25.  
  26. soup = BeautifulSoup(html, "html.parser")
  27. all_divs = soup.find('div', {'class' : 'sc-iELTvK bZNgpE'})
  28. job_profiles = all_divs.find_all('a')
  29.  
  30. print("-------------------------------------------------")
  31. print("|",end="")
  32. print("Market Name".center(15," "),end='')
  33. print("|",end='')
  34. print("Market Change".center(16," "),end='')
  35. print("|",end='')
  36. print("Market Price ".center(15," "),end='')
  37. print("|")
  38. print("-------------------------------------------------")
  39. for i in job_profiles:
  40.  
  41.     market_name=i.find('span',{'class':'market-name-text'})
  42.     temp=i.find('span',{'color':'#00C853','class':'sc-bwzfXH cFmqCk'})
  43.     if temp is not None:
  44.         market_change="+"+temp.text.encode('utf-8').decode('ascii', 'ignore')
  45.         #print(f"{market_name.text}(+{market_change})")
  46.     else:
  47.         temp=i.find('span',{'color':'#f44336','class':'sc-bwzfXH jsJuLQ'})
  48.         market_change="-"+temp.text.encode('utf-8').decode('ascii', 'ignore').replace("-","")
  49.         #print(f"{market_name.text}({market_change})")
  50.     price=i.find('span',{'class':'price-text ticker-price'}).text.encode('utf-8').decode('ascii', 'ignore')
  51.         #print(f"{market_name}(+{market_change})")
  52.     print("|")
  53.     print(market_name.text.strip('/inr').upper().center(15," "),end='|')
  54.     print(market_change.center(16," "),end='|')
  55.     print(price.center(15," "),"|")
  56.     print("-------------------------------------------------")
  57.     #print(f"{market_name.text.strip('/inr').upper()}   Market Change: (+{market_change})    Price: {price}")
  58.  
  59. #sys.stdout.close()
  60. driver.close() # closing the webdriver
  61.  
Advertisement
Add Comment
Please, Sign In to add comment