r - Post查询后提取结果

标签 r post screen-scraping

我正在尝试从中自动提取电力报价 site .一旦我设置了邮政编码(即:300),我就可以(手动)下载pdf文件

我正在使用 httr 包:

library(httr)
qr<- POST("http://www.qenergy.com.au/What-Are-Your-Options",
     query=list(postcode=3000))
res <- htmlParse(content(qr))

问题是文件 URL 不在查询响应中。请提供任何帮助。

最佳答案

试试这个

library(httr)
qr<- POST("http://www.qenergy.com.au/What-Are-Your-Options", 
          encode="form", 
          body=list(postcode=3000))
res <- content(qr)
pdfs <- as(res['//a[contains(@href, "pdf")]/@href'], "character")
head(pdfs)
# [1] "flux-content/qenergy/pdf/VIC price fact sheet jemena distribution zone business/Jemena-Freedom-Biz-5-Day-Time-of-Use-A210.pdf"  
# [2] "flux-content/qenergy/pdf/VIC price fact sheet jemena distribution zone business/Jemena-Freedom-Biz-7-Day-Time-of-Use-A250.pdf"  
# [3] "flux-content/qenergy/pdf/VIC price fact sheet jemena distribution zone business/Jemena-Freedom-Biz-Single-Rate-CL.pdf"          
# [4] "flux-content/qenergy/pdf/VIC price fact sheet jemena distribution zone business/Jemena-Freedom-Biz-Single-Rate.pdf"             
# [5] "flux-content/qenergy/pdf/VIC price fact sheet united energy distribution zone business/United-Freedom-Biz-5-Day-Time-of-Use.pdf"
# [6] "flux-content/qenergy/pdf/VIC price fact sheet united energy distribution zone business/United-Freedom-Biz-7-Day-Time-of-Use.pdf"

关于r - Post查询后提取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35779770/

相关文章:

r - 如何在R中的绘图中添加一条线

python - 关于 XPath 选择器的问题(针对 Scrapy)

r - 提取带点传递的数据框的名称

r - 扩大 x Axis 上刻度线之间的间距

php - 为什么我的数据总是正确的,并且复选框总是返回 "YES"?

json - 通过 HTTP POST 编码二进制数据的最有效方法是什么

c# - 套接字接收挂起

java - http 在页面加载完成之前获取 html

r - 如何对多列中的小写值对数据框进行子集化

ajax - 打开页面后如何使用 urllib2 或 Mechanize 发送 Ajax post 请求?