

# wait until the daily energy bar loads, or skip if 10 seconds have passedĮxpectation = EC.element_to_be_clickable((By.CSS_SELECTOR, '.nutrientTargetBar-text')) # if you set this to true the chrome window will not be displayedĭriver = webdriver.Chrome(options=options)ĭriver.find_element(by=By.NAME, value='username').send_keys(USERNAME)ĭriver.find_element(by=By.NAME, value='password').send_keys(PASSWORD)ĭriver.find_element(by=By.ID, value='login-button').click() Now youll have the unfortunate pleasure of knowing just exactly how many calories are in each of your grandmothers famous chocolate chip cookies. You are able to list out each ingredient and then break the recipe down into servings. # setup selenium (I am using chrome here, so chrome has to be installed on your system) The single greatest feature to be found in Cronometer is its recipe creation functionality. import chromedriver_autoinstallerįrom import Optionsįrom import Byįrom import expected_conditions as EC I've added comments explaining what every line does.
#Cronometer import recipe code
I wrote a piece of code that logs into cronometer and scrapes the daily energy value.

I personally like selenium as it is extremely easy to use, and you can actually see what the script is doing in a chrome browser in real-time. Scraping websites like these is an easy task with tools like requests-html module and selenium. This is basically what your requests call will see as well. If you disable the javascript and try to load cronometer, you will be greeted by the "Your web browser must have javascript enabled" message. You are using the requests module, which is an amazing tool for scraping static/server-side rendered content.Ĭronometer, however, is a javascript app. But using those specific URLs is not proving fruitful either.Īgain, sorry for my lack of knowledge, but how can I overcome this issue? I've tried looking at some online guides about Selenium, but so far I haven't been able to make sense of how I could use Selenium to log in when the issue isn't necessarily logging in (I don't think), but scraping the right webpage.

When I click on Diary, the URL changes from to /#diary, and Trends is /#trends, so on and so forth. One thing I did notice is that the URL does change slightly when I click on the tabs at the top, as you can see here: But it's only scraping data from the normal webpage (before you login), not my own personal webpage with the same URL. So after using session.post to send my credentials to the website, I'm using session.get to scrape data from my "profile". The problem is (I think) the URL for my personal homepage is the same URL for the website before logging in. Self.csrf_token = self.bs.find('input', attrs=)įrom what I can tell, this code successfully logs into with no issues. Self.bs = BeautifulSoup(self.r.text, 'html.parser') I have the following code (ignore the Hass/AppDaemon, I'm running this python script in Home Assistant): import as hassįrom import WebDriverWait Unfortunately, I'm having trouble actually scraping any data. I'm very new to Python, but using a few different online guides I've managed to stitch together some code that logs me into a website called (health tracking website/app, similar to myfitnesspal).
