Simple way to get table data in the request

blov · 2016-01-31 13:42:29 · 574 次点击    
这是一个分享于 2016-01-31 13:42:29 的资源,其中的信息可能已经有所发展或是发生改变。

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[url:rage:http://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!).


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

574 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传