This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"strings" | |
"github.com/antchfx/htmlquery" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outputBytes, err := json.Marshal(result) | |
errHandler(err) | |
fmt.Println(string(outputBytes)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')]") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Product struct { | |
Title string `json:"title"` | |
Description string `json:"description"` | |
Price string `json:"price"` | |
} | |
type ProductList []Product |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/antchfx/htmlquery" | |
) | |
func errHandler(err error) { | |
if err != nil { | |
panic(err) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'open-uri' | |
require 'json' | |
URL = "https://kernel-panic.me/scraping.html" | |
def main() | |
document = Nokogiri::HTML(open(URL)) | |
results = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'nokogiri' | |
document = Nokogiri::HTML(open(URL)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |