Home > Back-end >  Python Request generates a response, but response content decode results in a frame without data fie
Python Request generates a response, but response content decode results in a frame without data fie

Time:11-14

I am new to scraping the web. I am generating a request to the Seeking Alpha website and the frame being returned has all the fields on the webpage, but is missing the data. Here is some code to return the price of a stock say Apple.

#!/home/rajatkmitra/anaconda3.2020.11/bin/python
import requests as req
import json
import numpy as np
import random
from liveplot import live_plotter
from bs4 import BeautifulSoup


headers  = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'}
q_str= "https://seekingalpha.com/symbol/AAPL"
r = req.get(q_str,headers=headers,allow_redirects=True)
print(r.content.decode())

If you run this code the request returns with code 200 but the there is no sight of the actual stock price in the HTML frame. Am I missing the needed arguments in the req.get() method ?

CodePudding user response:

They have a "real-time" prices API you can use

import requests

r = requests.get('https://finance.api.seekingalpha.com/v2/real-time-prices?symbols=AAPL').json()
print(r['data'][0]['attributes']['last'])
  • Related