Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't know how to do #376

Open
purplecity opened this issue Sep 3, 2019 · 1 comment
Open

don't know how to do #376

purplecity opened this issue Sep 3, 2019 · 1 comment
Labels

Comments

@purplecity
Copy link

i want get the price (follow red frame)
image

	c.OnHTML("div[id=price]", func(e *colly.HTMLElement) {
		fmt.Printf("test----%+v\n",e)
		price,err := strconv.ParseFloat(e.Text,64)
		//price := e.Text
		fmt.Printf("********* price----%+v\n",price)

		if err != nil {

			fmt.Printf("parse err---%+v\n",err)

		}


	})

then Print

test----&{Name:div Text:@now@ attributes:[{Namespace: Key:id Val:price} {Namespace: Key:class Val:@UD_change@}] Request:0xc00013c280 Response:0xc000354240 DOM:0xc000558180 Index:0}
********* price----0
parse err---strconv.ParseFloat: parsing "@now@": invalid syntax
@ashkan90
Copy link

ashkan90 commented Sep 4, 2019

somehow it's getting wrong element's value. you can try to get value by css selector way like this;

c.OnHTML("div.price.clearfix > div.change > div.up", func(e *colly.HTMLElement) {
		fmt.Printf("test----%+v\n",e)
		price,err := strconv.ParseFloat(e.Text ,64)
		//price := e.Text
		fmt.Printf("********* price----%+v\n",price)

		if err != nil {

			fmt.Printf("parse err---%+v\n",err)

		}


})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants