Skip to content

Instantly share code, notes, and snippets.

View lowweihong's full-sized avatar

Low Wei Hong lowweihong

View GitHub Profile
from pyspider.libs.base_handler import *
class Handler(BaseHandler):
crawl_config = {
}
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
"Host": "www.similarweb.com",
"Upgrade-Insecure-Requests": "1",
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
import requests
from bs4 import BeautifulSoup
# Access credentials for google sheet and access the google sheet
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
import requests
from bs4 import BeautifulSoup
# Access credentials for google sheet and access the google sheet
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
import requests
HEADERS = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
"Origin": "https://www2.sgx.com",
"Referer": "https://www2.sgx.com/securities/securities-prices"}
# Start downloading stocks info from sgx
req = requests.get("https://api.sgx.com/securities/v1.1?excludetypes=bonds&params=nc,adjusted-vwap,b,bv,p,c,change_vs_pc,change_vs_pc_percentage,cx,cn,dp,dpc,du,ed,fn,h,iiv,iopv,lt,l,o,p_,pv,ptd,s,sv,trading_time,v_,v,vl,vwap,vwap-currency",
headers=HEADERS)
@lowweihong
lowweihong / websocket.py
Last active July 13, 2019 03:48
Web protocol example
from websocket import create_connection
import json
import pprint
# Initialize the headers needed for the websocket connection
headers = json.dumps({
'Date': 'Sun, 27 Aug 2017 09:42:15 GMT',
'Connection': 'upgrade',
'Host': 'www.kolumbus.no',
'Origin': 'https://www.kolumbus.no',