Unable to load URL

Question:

import requests
url = https://www.nseindia.com/get-quotes/equity?symbol=ACC
data = requests.get('https://www.nseindia.com/get-quotes/equity?symbol=ACC'')
print(data)

I’m trying to load data from above url but failed. How to do that? I got a invalid syntax error.

Asked By: Brijesh Chaurasia

||

Answers:

You mean this?

import requests
data = requests.get('https://www.nseindia.com/get-quotes/equity?symbol=ACC')
print(data)

Saying url = https://www.nseindia.com/get-quotes/equity?symbol=ACC is wrong because that is not a variable and has to be a string, plus you don’t even need it. You also have an extra ' behind your url.

Answered By: DialFrost

The decleration url = https://www.nseindia.com/get-quotes/equity?symbol=ACC

the actual value should be quoted, because it is a string like url = 'https://www.nseindia.com/get-quotes/equity?symbol=ACC'

Answered By: Anthony L

There’s two problems with your code.

First problem

url = https://www.nseindia.com/get-quotes/equity?symbol=ACC
  • Not a proper variable assignment
  • Missing quote for assigning string value

In this case url variable is a string so it should be:

url = "https://www.nseindia.com/get-quotes/equity?symbol=ACC"

Second problem

data = requests.get('https://www.nseindia.com/get-quotes/equity?symbol=ACC'')
  • Unnecessary extra ' at the end of your url string

Remove the extra ' and it should be:

data = requests.get('https://www.nseindia.com/get-quotes/equity?symbol=ACC')
print(data)

Before asking a question on stackoverflow please re-consider to contemplate on your code and check for syntax error.

Answered By: Pythonic User
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.