headzoo / surf

Stateful programmatic web browsing in Go.
MIT License
1.49k stars 160 forks source link

How do I click a tag ? #105

Closed owlinux1000 closed 6 years ago

owlinux1000 commented 6 years ago

I want to click a tag. How do I write the parameter of Click method ? I tried this way.

bow.Click("a[href=¥"https://example.com¥"]")
mbndr commented 6 years ago

Check if a error is returned. This can be the case if your element is not found.

err := bow.Click("a[href=\"https://example.com\"]")
if err != nil {
    // error handling here
}

This works fine for me.

I don't know what the Yen-symbol (¥) is doing there, but I think you have to escape the "

owlinux1000 commented 6 years ago

I'm sorry that the url I specified is wrong. I can click a tag. Exactly, I use Yen-symbol to escape " .

Thanks a lot!

mbndr commented 6 years ago

I didn't know it's possible to do ¥" instead of \"

owlinux1000 commented 6 years ago

Maybe it is because I use JIS keyboard layout.

owlinux1000 commented 6 years ago

If the URL contains the percent-encoding strings, Click method can't find matching expr ?

mbndr commented 6 years ago

Can you give an example?

I tried to click

<a href="http://localhost:8080/index.php?p=Hello%21">Link</a>

with

err := bow.Click("a[href=\"http://localhost:8080/index.php?p=Hello%21\"]")

and it worked fine.

I guess you can escape it like this:

u := "http://localhost:8080/index.php?" + url.PathEscape("p=Hello!")
err := bow.Click("a[href=\"" + u + "\"]")
owlinux1000 commented 6 years ago

I can't show my issue to you because of private task.

Umm... I can work your codes. Perhaps, I guess there are any other reasons. I'm going to try again.

owlinux1000 commented 6 years ago

I'll close this issue because I resolved my issue. However, refreshing of meta tag can't work in my task...