码迷,mamicode.com
首页 > 其他好文 > 详细

form submit

时间:2015-03-03 21:50:23      阅读:680      评论:0      收藏:0      [点我收藏+]

标签:

RHTMLForms在R高版本中不可用,解决如下

install_github("omegahat/RHTMLForms")

 提交表单,http://一定不能省略

u = "http://www.bing.com"
form = getHTMLFormDescription(u)[[1]];form

得到

HTML Form: http://cn.bing.com/search 
q: 

 制作一个form提交的function

bing_search = createFunction(form)

 这样bing_search()里面就能提交各式各样的搜索关键字,最后用

getHTMLLinks(bing_search("studio"))

这边得到

[1] "http://global.bing.com/search?q=rstudio&qs=ds&setmkt=en-us&setlang=en-us&FORM=SECNEN"
[2] "/?scope=web&FORM=HDRSC1"
[3] "/images/search?q=rstudio&FORM=HDRSC2"
[4] "/videos/search?q=rstudio&FORM=HDRSC3"
[5] "/knows/search?intlF=0&q=rstudio&FORM=HDRSC4"
[6] "/news/search?q=rstudio&FORM=HDRSC6"
[7] "/ditu/?q=rstudio&mkt=zh&FORM=HDRSC7"
[8] "/dict/search?intlF=0&q=rstudio&FORM=HDRSC8"
[9] "/explore?q=rstudio&FORM=HDRSC5"
[10] "javascript:void(0);"
[11] "/account/general?ru=http%3a%2f%2fcn.bing.com%3a80%2fsearch%3fq%3drstudio%26qs%3dds%26form%3dQBLH&FORM=SEFD"
[12] "/?FORM=Z9FD1"
[13] "/search?q=rstudio&qs=ds&intlF=1&FORM=TIPEN1"
[14] "/search?q=rstudio&qs=ds&intlF=&upl=zh-chs&FORM=TIPCN1"
[15] "http://www.rstudio.com/"
[16] "http://www.microsofttranslator.com/bv.aspx?ref=SERP&br=ro&mkt=zh-CN&dl=zh&lp=EN_ZH-CHS&a=http%3a%2f%2fwww.rstudio.com%2f"
[17] "http://www.rstudio.com/"
[18] "http://www.rstudio.com/shiny/"
[19] "http://www.rstudio.com/about/"
[20] "http://www.rstudio.com/about/dmca.html"
[21] "http://www.rstudio.com/training/"
[22] "http://www.rstudio.com/products/rpackages/"
[23] "http://www.rstudio.com/products/rstudio/"
[24] "http://www.rstudio.com/ide/screenshots/"
[25] "http://www.rstudio.com/products/rstudio/"
[26] "http://www.microsofttranslator.com/bv.aspx?ref=SERP&br=ro&mkt=zh-CN&dl=zh&lp=EN_ZH-CHS&a=http%3a%2f%2fwww.rstudio.com%2fproducts%2frstudio%2f"
[27] "http://zh.wikipedia.org/wiki/RStudio"
[28] "http://www.baike.com/wiki/RStudio"
[29] "http://mydown.yesky.com/soft/255/255724.shtml"
[30] "http://mydown.yesky.com/soft/255/255724.shtml"
[31] "http://more.tianjimedia.com/soft/down.jsp?id=255724&f=bing&path=http%3A%2F%2Fwww.r-tt.com%2Fdownloads%2FRStudio7.exe"
[32] "http://blog.sina.com.cn/s/blog_403aa80a01019uwt.html"
[33] "http://www.oschina.net/p/rstudio"
[34] "http://www.r-studio.com/"
[35] "http://www.microsofttranslator.com/bv.aspx?ref=SERP&br=ro&mkt=zh-CN&dl=zh&lp=EN_ZH-CHS&a=http%3a%2f%2fwww.r-studio.com%2f"
[36] "http://www.liangchan.net/liangchan/1123.html"
[37] "https://rstudio.org/"
[38] "http://www.microsofttranslator.com/bv.aspx?ref=SERP&br=ro&mkt=zh-CN&dl=zh&lp=EN_ZH-CHS&a=https%3a%2f%2frstudio.org%2f"
[39] "https://rstudio.org/ide/"
[40] "http://www.microsofttranslator.com/bv.aspx?ref=SERP&br=ro&mkt=zh-CN&dl=zh&lp=EN_ZH-CHS&a=https%3a%2f%2frstudio.org%2fide%2f"
[41] "http://xiazai.zol.com.cn/detail/28/271400.shtml"
[42] "/search?q=rstudio+%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81&FORM=QSRE1"
[43] "/search?q=rstudio%e7%a0%b4%e8%a7%a3%e7%89%88&FORM=QSRE2"
[44] "/search?q=rstudio+mac+chinese&FORM=QSRE3"
[45] "/search?q=rstudio%e4%b8%8b%e8%bd%bd&FORM=QSRE4"
[46] "/search?q=rstudio+download&FORM=QSRE5"
[47] "/search?q=shiny+rstudio&FORM=QSRE6"
[48] "/search?q=rstudio+0.98+%e4%b8%8b%e8%bd%bd&FORM=QSRE7"
[49] "/search?q=linux+rstudio+server&FORM=QSRE8"
[50] "/search?q=rstudio&qs=ds&first=9&FORM=PERE"
[51] "/search?q=rstudio&qs=ds&first=19&FORM=PERE1"
[52] "/search?q=rstudio&qs=ds&first=29&FORM=PERE2"
[53] "/search?q=rstudio&qs=ds&first=39&FORM=PERE3"
[54] "/search?q=rstudio&qs=ds&first=9&FORM=PORE"
[55] "/search?q=%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d&form=ENRC1"
[56] "/search?q=%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d&form=ENRC1"
[57] "/search?q=%e7%a3%81%e7%9b%98&form=ENRC1"
[58] "/search?q=%e7%a3%81%e7%9b%98&form=ENRC1"
[59] "/search?q=%e6%95%b0%e6%8d%ae%e6%b5%81&form=ENRC1"
[60] "/search?q=%e6%95%b0%e6%8d%ae%e6%b5%81&form=ENRC1"
[61] "/search?q=EasyRecovery&form=ENRC2"
[62] "/search?q=EasyRecovery&form=ENRC2"
[63] "/search?q=%e9%a1%b6%e5%b0%96%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d%e8%bd%af%e4%bb%b6&form=ENRC2"
[64] "/search?q=%e9%a1%b6%e5%b0%96%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d%e8%bd%af%e4%bb%b6&form=ENRC2"
[65] "/search?q=diskman&form=ENRC2"
[66] "/search?q=diskman&form=ENRC2"
[67] "/search?q=%e6%95%88%e7%8e%87%e6%ba%90&form=ENRC3"
[68] "/search?q=%e6%95%88%e7%8e%87%e6%ba%90&form=ENRC3"
[69] "/search?q=R-Studio V4.0 build 124047&form=ENRC3"
[70] "/search?q=R-Studio V4.0 build 124047&form=ENRC3"
[71] "/search?q=R-StudioV3.5Build123501%e6%b1%89%e5%8c%96%e7%89%88&form=ENRC3"
[72] "/search?q=R-StudioV3.5Build123501%e6%b1%89%e5%8c%96%e7%89%88&form=ENRC3"
[73] "/search?q=rstudio+%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81&FORM=R5FD"
[74] "/search?q=rstudio%e7%a0%b4%e8%a7%a3%e7%89%88&FORM=R5FD1"
[75] "/search?q=rstudio+mac+chinese&FORM=R5FD2"
[76] "/search?q=rstudio%e4%b8%8b%e8%bd%bd&FORM=R5FD3"
[77] "/search?q=rstudio+download&FORM=R5FD4"
[78] "/search?q=shiny+rstudio&FORM=R5FD5"
[79] "/search?q=rstudio+0.98+%e4%b8%8b%e8%bd%bd&FORM=R5FD6"
[80] "/search?q=linux+rstudio+server&FORM=R5FD7"
[81] "/search?q=rstudio&qs=ds&hta=off"
[82] "http://go.microsoft.com/fwlink/?LinkId=248686&CLCID=804"
[83] "http://go.microsoft.com/?linkid=9844344"
[84] "http://onlinehelp.microsoft.com/zh-CN/bing/ff808535.aspx"
[85] "http://go.microsoft.com/fwlink/?LinkID=246338&CLCID=804"

中间[13]-[81]是有效链接

如果只是想提取我们需要的链接呢?用xpath,结果更精确,但是也损失了不少信息(怎么处理?)

xpq = "//a/@href[starts-with(.,‘/search?q=rstudio‘)]"
getHTMLLinks(txt,xpQuery = xpq)

 

[1] "/search?q=rstudio&qs=ds&intlF=1&FORM=TIPEN1"
[2] "/search?q=rstudio&qs=ds&intlF=&upl=zh-chs&FORM=TIPCN1"
[3] "/search?q=rstudio+%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81&FORM=QSRE1"
[4] "/search?q=rstudio%e7%a0%b4%e8%a7%a3%e7%89%88&FORM=QSRE2"
[5] "/search?q=rstudio+mac+chinese&FORM=QSRE3"
[6] "/search?q=rstudio%e4%b8%8b%e8%bd%bd&FORM=QSRE4"
[7] "/search?q=rstudio+download&FORM=QSRE5"
[8] "/search?q=rstudio+0.98+%e4%b8%8b%e8%bd%bd&FORM=QSRE7"
[9] "/search?q=rstudio&qs=ds&first=9&FORM=PERE"
[10] "/search?q=rstudio&qs=ds&first=19&FORM=PERE1"
[11] "/search?q=rstudio&qs=ds&first=29&FORM=PERE2"
[12] "/search?q=rstudio&qs=ds&first=39&FORM=PERE3"
[13] "/search?q=rstudio&qs=ds&first=9&FORM=PORE"
[14] "/search?q=rstudio+%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81&FORM=R5FD"
[15] "/search?q=rstudio%e7%a0%b4%e8%a7%a3%e7%89%88&FORM=R5FD1"
[16] "/search?q=rstudio+mac+chinese&FORM=R5FD2"
[17] "/search?q=rstudio%e4%b8%8b%e8%bd%bd&FORM=R5FD3"
[18] "/search?q=rstudio+download&FORM=R5FD4"
[19] "/search?q=rstudio+0.98+%e4%b8%8b%e8%bd%bd&FORM=R5FD6"
[20] "/search?q=rstudio&qs=ds&hta=off"

form submit

标签:

原文地址:http://www.cnblogs.com/Dearc/p/4311818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!