ericchiang / pup

Parsing HTML at the command line
MIT License
8.09k stars 257 forks source link

Selector combination don't work as expected #190

Open mszet opened 1 year ago

mszet commented 1 year ago

Get Links that start with "vivaldi-stable_6" and end in "_amd64.deb" according the last example in MDN

$ baseurl='https://repo.vivaldi.com/stable/deb/pool/main/' $ curl -s "$baseurl" |pup 'a[href^=vivaldi-stable_6][href$=_amd64.deb] attr{href}' vivaldi-stable_6.1.3035.111-1_amd64.deb vivaldi-stable_6.1.3035.111-1_arm64.deb vivaldi-stable_6.1.3035.111-1_armhf.deb

Thank you for your attention. Greetings, mszet

gromgit commented 1 year ago

Which version of pup are you using? Chaining attribute selectors works fine for me:

$ pup --version
0.4.0

$ baseurl='https://repo.vivaldi.com/stable/deb/pool/main/'

$ curl -s "$baseurl" |pup 'a[href^=vivaldi-stable_6] attr{href}'
vivaldi-stable_6.1.3035.111-1_amd64.deb
vivaldi-stable_6.1.3035.111-1_arm64.deb
vivaldi-stable_6.1.3035.111-1_armhf.deb
vivaldi-stable_6.1.3035.204-1_amd64.deb
vivaldi-stable_6.1.3035.204-1_arm64.deb
vivaldi-stable_6.1.3035.204-1_armhf.deb

$ curl -s "$baseurl" |pup 'a[href^=vivaldi-stable_6][href$=_amd64.deb] attr{href}'
vivaldi-stable_6.1.3035.111-1_amd64.deb
vivaldi-stable_6.1.3035.204-1_amd64.deb
mszet commented 1 year ago

Which version of pup are you using? Chaining attribute selectors works fine for me: $ pup --version 0.4.0

It is the same from debian bookworm. Now i have cloned and compiled myself, but the result remains the same:

$git clone https://github.com/ericchiang/pup.git
Klone nach 'pup'...
remote: Enumerating objects: 952, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 952 (delta 0), reused 3 (delta 0), pack-reused 947
Empfange Objekte: 100% (952/952), 3.78 MiB | 8.71 MiB/s, fertig.
Löse Unterschiede auf: 100% (346/346), fertig.

$ cd pup
$ go build .
go: downloading github.com/fatih/color v1.0.0
go: downloading github.com/mattn/go-colorable v0.0.5
go: downloading golang.org/x/text v0.0.0-20160719205907-0a5a09ee4409
go: downloading github.com/mattn/go-isatty v0.0.0-20151211000621-56b76bdf51f7

$ ls -l ./pup
-rwxr-xr-x 1 michael michael 3710054 25. Jul 13:51 ./pup

$ baseurl='https://repo.vivaldi.com/stable/deb/pool/main/'
$ curl -s "$baseurl" |./pup 'a[href^=vivaldi-stable_6][href$=_amd64.deb] attr{href}'
vivaldi-stable_6.1.3035.111-1_amd64.deb
vivaldi-stable_6.1.3035.111-1_arm64.deb
vivaldi-stable_6.1.3035.111-1_armhf.deb
vivaldi-stable_6.1.3035.204-1_amd64.deb
vivaldi-stable_6.1.3035.204-1_arm64.deb
vivaldi-stable_6.1.3035.204-1_armhf.deb

Thank you for your attention. Greetings, mszet

gromgit commented 1 year ago

Not sure what happened there, but since you have a local source directory, try updating the dependencies (which were last bumped almost a year ago):

go get -u
go mod tidy
go build .

then try your test again.

mszet commented 1 year ago

No changes:

$ go get -u
go: downloading golang.org/x/net v0.14.0
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading github.com/fatih/color v1.15.0
go: downloading golang.org/x/text v0.12.0
go: downloading github.com/mattn/go-isatty v0.0.19
go: downloading golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3
go: downloading golang.org/x/sys v0.11.0
go: upgraded github.com/fatih/color v1.0.0 => v1.15.0
go: upgraded github.com/mattn/go-colorable v0.0.5 => v0.1.13
go: upgraded github.com/mattn/go-isatty v0.0.0-20151211000621-56b76bdf51f7 => v0.0.19
go: upgraded golang.org/x/net v0.0.0-20160720084139-4d38db76854b => v0.14.0
go: upgraded golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3 => v0.11.0
go: upgraded golang.org/x/text v0.0.0-20160719205907-0a5a09ee4409 => v0.12.0

$ go mod tidy
$ go build .

$ baseurl='https://repo.vivaldi.com/stable/deb/pool/main/'
$ curl -s "$baseurl" |./pup 'a[href^=vivaldi-stable_6][href$=_amd64.deb] attr{href}'
vivaldi-stable_6.1.3035.111-1_amd64.deb
vivaldi-stable_6.1.3035.111-1_arm64.deb
vivaldi-stable_6.1.3035.111-1_armhf.deb
vivaldi-stable_6.1.3035.204-1_amd64.deb
vivaldi-stable_6.1.3035.204-1_arm64.deb
vivaldi-stable_6.1.3035.204-1_armhf.deb
vivaldi-stable_6.1.3035.257-1_amd64.deb
vivaldi-stable_6.1.3035.257-1_arm64.deb
vivaldi-stable_6.1.3035.257-1_armhf.deb

What system are you using?

Thank you for your attention. Greetings, mszet

gromgit commented 1 year ago

Ubuntu 22.04, but I just realized that I've been testing against my own fork instead of the original source. :grinning:

This was addressed by https://github.com/ericchiang/pup/pull/139, so you'll want to pull it into your own fork. If you don't have your own fork, patch the original source as follows:

curl -sL "https://github.com/ericchiang/pup/commit/f9e1b3ed7dfa615dd5709c6aa78aab2c7c63c190.patch" | patch -p1

then build and try again.