diff --git a/Makefile b/Makefile index dee04fe..c110fd1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=0.2.0 +VERSION=0.2.1 all: lint test @@ -9,15 +9,14 @@ lint: @go fmt ./... @golint ./... -test: build +test: test-src test-cli +test-src: + @go test ./... +test-cli: build @./htmltable2csv -v @./htmltable2csv -source "./scraper/fixture/test1.html" -selector "table > tbody > tr" -csv data_file.csv @./htmltable2csv -source "https://www.w3schools.com/html/html_tables.asp" -selector "#customers > tbody > tr" -csv data_url.csv -test-all: - @go test ./... - @make test - release: git tag -a v${VERSION} -m "Version ${VERSION}" git push origin v${VERSION} diff --git a/README.md b/README.md index a02cc6f..efb0416 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ Flags: The table css selector -source string The filepath or website url + -trim + Trim the whitespace for each table column -v Print the version and exit Examples: diff --git a/main.go b/main.go index eada04f..f79752d 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ func main() { flagVersion := flag.Bool("v", false, "Print the version and exit") flagSource := flag.String("source", "", "The filepath or website url") flagSelector := flag.String("selector", "", "The table css selector") + flagTrim := flag.Bool("trim", false, "Trim the whitespace for each table column") flagCSV := flag.String("csv", "", "The csv filename. if empty, print csv to stdout") flag.Usage = usage flag.Parse() @@ -52,6 +53,7 @@ func main() { scraper := htmltable2csv.Scraper{} scraper.Source = *flagSource scraper.Selector = *flagSelector + scraper.Trim = *flagTrim _, err = scraper.Scrape() if err != nil { fmt.Println(err) diff --git a/package.json b/package.json index 4d8fef8..9be9b51 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "htmltable2csv", - "version": "0.2.0", + "version": "0.2.1", "description": "htmltable2csv is a tool to parse a html table and store the data as csv. It can be written to a file or print out to stdout", "scripts": { "test": "make test" diff --git a/scraper/fixture/test2.html b/scraper/fixture/test2.html new file mode 100644 index 0000000..40bd247 --- /dev/null +++ b/scraper/fixture/test2.html @@ -0,0 +1,50 @@ +
key | +value | +
+ foo + | ++ 1 + | +
+ bar + | ++ 2 + + + + + | +
+ baz + + + + | ++ + + 3 + + + + + + + + | +