How to add variable to URL?

I’m trying to collect data from a website. I have an Excel file containing all the different extensions for the website. F.i. I have a script that succesfully extracts the HTML from the site, but now I want to do it automatically for all the extensions. However, when I say:

 siteExtension = "example2" 
 url = ("")
 r = requests.get(url)

instead of:

url = ("")
r = requests.get(url)

I get an error code. Do you guys have any suggestions how to do this? Thanks in advance!


You need to concatenate the value of siteExtension to your url string. You can do this in a number of ways, but here are the two most common:

url = "" + siteExtension

or, the more ubiquitous form:

url = "{}".format(siteExtension)

Leave a Reply

Your email address will not be published. Required fields are marked *