

The first function calls the website of a selected stock and collects the cookies and crumb. In my case, when connecting to the website, the cookiejarĬontains a single cookie element ( B), which we will send with our request.Īdditionally, they use something called a crumb, which is another identifier, but this one is send in the url, when requesting the historical csv file! Requests handles cookies in a cookiejar object, which essentially is a python dictionary but cookiejar sounds way cooler, right?! The yahoo finance website uses cookies and restricts access to users (scripts) unless they are sending the proper cookie to their server.

Now, lets talk a little about cookies 🍪 and crumbs 🍴🍪Ĭookies are small text snippets websites usually save on your computer, they can contain for example identifiers such as session IDs. Import re # regular expressions are necessary for finding the crumb (more on crumbs later)įrom datetime import datetime # string to datetime object conversionįrom time import mktime # mktime transforms datetime objects to unix timestamps Import requests # ()įrom bs4 import BeautifulSoup # beautiful soup handles the html to text conversion and more
