Skip to content

Instantly share code, notes, and snippets.

View kitz99's full-sized avatar

Bogdan Timofte kitz99

View GitHub Profile
require 'nokogiri'
require 'open-uri'
require 'json'
URL = "https://kernel-panic.me/scraping.html"
def main()
document = Nokogiri::HTML(open(URL))
results = []
package main
import (
"github.com/antchfx/htmlquery"
)
func errHandler(err error) {
if err != nil {
panic(err)
}
type Product struct {
Title string `json:"title"`
Description string `json:"description"`
Price string `json:"price"`
}
type ProductList []Product
result := ProductList{}
productNodes := htmlquery.Find(doc, "//ul[@class='products']/li")
for _, p := range productNodes {
var currentProduct Product
titleNode := htmlquery.FindOne(p, "div/div[@class='product-header']")
currentProduct.Title = strings.TrimSpace(htmlquery.InnerText(titleNode))
descriptionNode := htmlquery.FindOne(p, "div/div[@class='product-body']/p[contains(@class, 'description')]")
outputBytes, err := json.Marshal(result)
errHandler(err)
fmt.Println(string(outputBytes))
package main
import (
"encoding/json"
"fmt"
"strings"
"github.com/antchfx/htmlquery"
)
function withoutDestruct(config) {
var opt1 = config.opt1 !== undefined ? config.opt1 : "foo";
var opt2 = config.opt2 !== undefined ? config.opt2 : "foobar";
var opt4 = config.opt3 !== undefined ? config.opt3 : "baz";
console.log(opt1, opt2, opt3);
}
withoutDestruct({opt1: "hello ", opt2: "world", opt3: "!"}); // > "hello world!"
const data = "This sentence uses word1 and also word2"
// using regex groups to extract word1 and word2
var result = data.match(/^This sentence uses (.*) and also (.*)$/);
const opt1 = resutt[1];
const opt2 = result[2];
// using destructuring
const { 3: opt1, 6: opt2 } = data.split(' ');
const obj = { opt1: ["a", "b", "c", "d"], opt2: {opt21: "aaaa", opt22: false}, opt3: "http://exaple.com" }
JSON.stringify(obj, null, 4);
// "{
// "opt1": [
// "a",
// "b",
// "c",
// "d"
version: '3'
services:
db:
image: mysql:5.7
volumes:
- ./data_dir:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: choosepasswd