Q:

Using requests in a loop provides different HTML than using it outside of the loop

I'm attempting to use Python to scrape historic exchange rates from a website.
If I scrape the site manually:
url = "https://www.x-rates.com/historical/?from=USD&amount=1&date=2018-07-12"
page = requests.get(url, timeout=5)
soup = BeautifulSoup(page.content, "html.parser")
table = soup.find("tbody")

The result is the correct HTML I'm looking for.
However, if I use the same block inside this loop:
for d in date_generated:
    date = str(d).replace("00:00:00", "")
    url = "https://www.x-rates.com/historical/?from=USD&amount=1&date=" + date
    page = requests.get(url, timeout=5)
    soup = BeautifulSoup(page.content, "html.parser")
    table = soup.find("tbody")

    for i,x in zip(table.find_all("a"), table.find_all("td", class_="")):
        time.sleep(3)
        request += 1
        elapsed_time = time.time() - start_time
        print(i.text.strip(), x.text.strip())

I don't get the correct HTML content. The generated URL's work, and I get a 200 status_code but a NoneType object is returned at the second loop when it attempts to use the table, indicating that it never got the HTML I wanted in the first place (But I do get it if I run it out of the loop). 
For those asking, here's how the dates are generated.
   start_time = time.time()
   start = datetime.datetime.strptime("2018-07-07", "%Y-%m-%d")
   end = datetime.datetime.strptime("2018-07-12", "%Y-%m-%d")
   date_generated = [start + datetime.timedelta(days=p) for p in range(0, (end- 
   start).days)]

A:

for the sake of this answer lets say that the value of d is equal to 2018-07-07 00:00:00. 
Nonetheless, when you run:
date = str(d).replace("00:00:00", "")

you forget the space between 2018-07-07 and 00:00:00. 
So you should replace this line with:
date = str(d).replace(" 00:00:00", "")

Hope this solves your problem :)

