Skip to content

Instantly share code, notes, and snippets.

/* *******************************************************************************************
* PUPPETEER
* https://pptr.dev/
* ******************************************************************************************* */
// When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win)
// that is guaranteed to work with the API.
npm install puppeteer
@ilyazub
ilyazub / puppeteer-reuse-cookie-in-http-request-from-node.js
Last active April 4, 2024 23:56
Reuse `puppeteer` cookies in `tough-cookie` and `got`
#' Convert degrees to radians
deg2rad <- function(deg){
rads <- deg*pi/180
return(rads)
}
#' Calculates the geodesic distance between two points specified by
#' radian latitude/longitude using the
#' Spherical Law of Cosines (slc)
#'
"""Extract nested values from a JSON tree."""
def json_extract(obj, key):
"""Recursively fetch values from nested JSON."""
arr = []
def extract(obj, arr, key):
"""Recursively search for values of key in JSON tree."""
if isinstance(obj, dict):
exports.scrapeTwittter = async (req, res) => {
let ret = [];
const { search } = req.query;
try {
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
const page = await browser.newPage();
await page.goto(`https://twitter.com/search?f=tweets&vertical=default&q=${search}&src=typd`);
//set viewport for the autoscroll function
await page.setViewport({
width: 1200,
@AdamSpannbauer
AdamSpannbauer / wordcloud2_clickeven_with_reset.R
Created January 12, 2018 19:15
wordcloud2 example of click event and input resetting
#current preferred version of wc2
devtools::install_github("Lchiffon/wordcloud2#32")
#function to give wordcloud2 click interactivity
wc2ClickedWord = function(cloudOutputId, inputId) {
#ARGUMENTS
# - cloudOutputId: string; outputId of wordcloud2 obj being rendered (should be identical to the value passed to wordcloud2Output)
# - inputId: string; inputId of word clicked on (ie you will reference in server the word by input$inputId)
#OUPUT
# - referencing input in server will return a string of form word:freq (same as hover info shown in wordcloud; ie 'super:32')
@ebidel
ebidel / monitor_internet_connection.js
Last active February 28, 2018 18:32
Puppeteer: monitor status of internet connectivity using headless Chrome
Moved to https://github.com/ebidel/puppeteer-examples/blob/master/monitor_internet_connection.js
@theriley106
theriley106 / congressEducation.py
Created December 9, 2017 19:17
Web Scraping congress education information
import requests
import bs4
import re
import json
listOfCongress = []
url = 'https://www.govtrack.us/congress/members/current?sort=sortname&page=1&faceting=false&allow_redirect=false&do_search=1'
congressCount = requests.get(url).json()['total']
information = {}
@fxi
fxi / README.md
Last active April 18, 2019 15:48
Experimental work on forked computation in shiny app using the package "parallel".

Shiny asynchronous jobs

Experiemental work on forked computation in shiny app using the package "parallel".

Does not work on windows.

Example

@daattali
daattali / rselenium-taxonomer-1-upload.R
Last active June 24, 2019 09:00
Use RSelenium to automatically upload many FASTQ files, submit each to "full analysis" when it's ready, and download the analyzed file on Taxonomer.com
# This script uploads all the FAST files to the taxonomer server (only one file can be uploaded at a time)
# Assumes that you have RSelenium package installed and that you've got a simple selenium example to work
if (FALSE) {
fastq_files <- c(
list.files(# WHERE ARE THE FILES?, pattern = "fastq.gz$", full.names = TRUE)
)
login_password <- "" # what is my password???
library(RSelenium)