JosefStepanek

Tipranks.com smart score extraction

Dec 28th, 2022
2,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | Source Code | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3.  
  4. id = 'bxc'
  5. url = f'https://www.tipranks.com/stocks/{id}/stock-analysis'
  6.  
  7. headers = {'User-Agent': 'Googlebot-Mobile/2.1 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)'}
  8.  
  9. response = requests.get(url, headers=headers)
  10.  
  11. soup = BeautifulSoup(response.text, 'html.parser')
  12.  
  13. og_description = soup.find('meta', attrs={'property': 'og:description'})['content']
  14.  
  15. import re
  16.  
  17. match = re.search(r'Smart Score of (\d+)', og_description)
  18. score = match.group(1)
  19.  
  20. print(f'The Tipranks.com Smart Score of {id} is {score}')
  21.  
Advertisement
Add Comment
Please, Sign In to add comment