I am new in Golang and I have my simple HTML table with IDs and URLs.
When I post, I have it in request.Form
map[urlhttp://www.example.net/ http://www.example2.net/] url_id:[1 2]]
Any simple way to not parse it manually? any method to join it?
Thanks in advance.
评论:
izuriel:
I went to Google and searched "golang html parser." I used "golang" because just "go" tends to return fewer relevant results, (IMO). The first result is a godoc page for golang.org/x/net/http which provides a parser for HTML fragments from an io.Reader. Then the second result for a library called "goquery" which could be more of what your looking for. So a simple Google search would have already answered your question. So ask Google first!
Now, if your scraping an HTML page chances are your not intended to be doing so so, depending on user agreements or other things legal I don't know that much about, be careful. If it's yours, or your companies you should make this a data endpoint and avoid scraping. Lastly there are services that turn arbitrary webpages into JSON end points that you can look into as well.
Final note, try, try, try to not scrape. Scraping is far more fickle than other ways to get data. If classes or elements change your program breaks. And it's more likely that the page can change than an API. Most of the time the API itself implies some form of consistency (I didn't say always!).
