Skip to content

Instantly share code, notes, and snippets.

@agawronski
agawronski / whoop-goldencheetah.py
Created September 22, 2020 04:02 — forked from jkreileder/whoop-goldencheetah.py
Python 3 script to export WHOOP Strap recovery data for use with Golden Cheetah
#!/usr/bin/env python3
import requests # for getting URL
import json # for parsing json
from datetime import datetime # datetime parsing
import pytz # timezone adjusting
import csv # for making csv files
import os
#################################################################
from selenium import webdriver #Importing the web driver from selenium library
browser = webdriver.PhantomJS(executable_path=r'C:\Python27\phantomjs-2.1.1-windows\bin\phantomjs.exe') #Setting our virtual browser with PhantomJS.
#Note: If file path of phantomjs path is not set then we need to pass its executable_path as argument. In windows phantomjs.exe and phantomjs otherwise.
browser.set_window_size(1120, 550) #Resize the browser to desired size. Try out this code by removing this line and see the screenshot.
browser.get("http://testing-ground.scraping.pro/login") #Getting the response from http://testing-ground.scraping.pro/login.
#Go to this URL and see expectations also explore the dom structure of the page.
browser.find_element_by_id('usr').send_keys("admin") #Finding input box of username by its id and sending 'admin' as a user name.
browser.find_element_by_id('pwd').send_keys("12345") #Finding input box of the password by its id and sending '12345' as a password.
browser.find_element_by_xpath("//*
import csv
import requests
from BeautifulSoup import BeautifulSoup
url = 'http://www.worldometers.info/world-population/population-by-country/'
response = requests.get(url) #Getting the response from mentioned URL using get() method of requests
html = response.content
soup = BeautifulSoup(html)
table = soup.find('table', attrs={'id': 'example2'}) #From BeautifulSoup of HTML content, finding the tbody(data of table) of the desired table having specific attributes, here desired table has 'example2' as idtbody = table.find('tbody')
list_of_rows = []
for row in tbody.findAll('tr')[0:]: #line 11-16, Traversing every row('tr') and every cell of a row ('td') in table and making list of rows list_of_cells = []