-
Open a browser
# start an instance of firefox with selenium-webdriver driver = Selenium::WebDriver.for :firefox # :chrome -> chrome # :ie -> iexplore
- Go to a specified URL
// read the response body to a variable | |
bodyBytes, _ := ioutil.ReadAll(response.Body) | |
// Use io.Copy to just dump the response body to the file. This supports huge files | |
err := ioutil.WriteFile("tmp/asdf.png", bodyBytes, 0644) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Captcha image saving success!") | |
//reset the response body to the original unread state | |
response.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) |
def findNull(row:Row):String = { | |
if (row.anyNull) { | |
val indices = (0 to row.length-1).toArray.filter(i => row.isNullAt(i)) | |
indices.mkString(",") | |
} | |
else "-1" | |
} | |
sqlContext.udf.register("findNull", findNull _) | |
df = df.withColumn("MissingGroups",callUDF("findNull",struct(df.columns.map(df(_)) : _*))) |
def splitDataFrameList(df,target_column,separator): | |
''' df = dataframe to split, | |
target_column = the column containing the values to split | |
separator = the symbol used to perform the split | |
returns: a dataframe with each entry for the target column separated, with each element moved into a new row. | |
The values in the other columns are duplicated across the newly divided rows. | |
''' | |
def splitListToRows(row,row_accumulator,target_column,separator): | |
split_row = row[target_column].split(separator) |
### Locating UI elements ### | |
# By ID | |
<div id="coolestWidgetEvah">...</div> | |
element = driver.find_element_by_id("coolestWidgetEvah") | |
or | |
from selenium.webdriver.common.by import By | |
element = driver.find_element(by=By.ID, value="coolestWidgetEvah") | |
# By class name: |
# List unique values in a DataFrame column | |
# h/t @makmanalp for the updated syntax! | |
df['Column Name'].unique() | |
# Convert Series datatype to numeric (will error if column has non-numeric values) | |
# h/t @makmanalp | |
pd.to_numeric(df['Column Name']) | |
# Convert Series datatype to numeric, changing non-numeric values to NaN | |
# h/t @makmanalp for the updated syntax! |
REPLACE(REPLACE(REPLACE(mycolumn, CHAR(9), ''), CHAR(10), ''), CHAR(13), '') as 'mycolumn' |
Verifying my Blockstack ID is secured with the address 1MeCc7ajem6iSuiDGFMLgh9kQYp8okC5w4 https://explorer.blockstack.org/address/1MeCc7ajem6iSuiDGFMLgh9kQYp8okC5w4 |
# By Jake VanderPlas | |
# License: BSD-style | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def discrete_cmap(N, base_cmap=None): | |
"""Create an N-bin discrete colormap from the specified input map""" |