Skip to content

Instantly share code, notes, and snippets.

View kitz99's full-sized avatar

Bogdan Timofte kitz99

View GitHub Profile
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!"
package main
import (
"encoding/json"
"fmt"
"strings"
"github.com/antchfx/htmlquery"
)
outputBytes, err := json.Marshal(result)
errHandler(err)
fmt.Println(string(outputBytes))
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')]")
type Product struct {
Title string `json:"title"`
Description string `json:"description"`
Price string `json:"price"`
}
type ProductList []Product
package main
import (
"github.com/antchfx/htmlquery"
)
func errHandler(err error) {
if err != nil {
panic(err)
}
require 'nokogiri'
require 'open-uri'
require 'json'
URL = "https://kernel-panic.me/scraping.html"
def main()
document = Nokogiri::HTML(open(URL))
results = []
results = []
products = document.xpath("//ul[@class='products']/li")
products.each do |p|
json_product = {}
json_product[:title] = p.xpath("div/div[@class='product-header']").text.strip
json_product[:description] = p.xpath("div/div[@class='product-body']/p[contains(@class, 'description')]").text.strip
json_product[:price] = p.xpath("div/div[@class='product-footer']/p[contains(@class, 'price')]").text.strip
results << json_product
end
require 'open-uri'
require 'nokogiri'
document = Nokogiri::HTML(open(URL))
func deleteRecord(id int64) error {
qryString := fmt.Sprintf("DELETE from posts WHERE id = %d", id)
fmt.Printf("Query: %v\n", qryString)
_, err := roachConnection.Exec(qryString)
return err
}