Home > OS >  Unable to load URL
Unable to load URL

Time:08-21

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.

CodePudding user response:

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.

CodePudding user response:

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.

CodePudding user response:

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'

  • Related