R - Scraping aspx web error

强颜欢笑 提交于 2019-12-12 04:32:33

问题


library(rvest)
url <- "http://bet.hkjc.com/racing/pages/odds_wp.aspx?date=14-12-2016&venue=HV&raceno=1&lang=en"

R1odds <- url %>% read_html() %>%
  html_nodes("table") %>%
  .[[2]] %>%
  html_table(fill=TRUE)
R1odds

I got this error message:

Error: input conversion failed due to input error, bytes 0x3C 0x2F 0x6E 0x6F [6003]

How to solve this?


回答1:


For others who might run into something like this in a non-gambling context here's the solution to get round the nulls. You'll have to deal with your gambling data issue on your own:

library(rvest)
library(curl)

url <- "http://bet.hkjc.com/racing/pages/odds_wp.aspx?date=14-12-2016&venue=HV&raceno=1&lang=en"

pg <- curl_fetch_memory(url)

pg$content %>%
  readBin(what=character()) %>%
  read_html() -> doc

html_nodes(doc, "table")
## {xml_nodeset (47)}
##  [1] <table width="776" border="0" cellspacing="0" cellpadding="0">\n  < ...
##  [2] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
##  [3] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
##  [4] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
##  [5] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
##  [6] <table width="776" border="0" cellspacing="0" cellpadding="0">\n  < ...
##  [7] <table width="776" border="0" cellspacing="0" cellpadding="0">\n  < ...
##  [8] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
##  [9] <table width="100%" border="0" cellspacing="0" cellpadding="0" clas ...
## [10] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [11] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [12] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [13] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [14] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [15] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [16] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [17] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [18] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [19] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## [20] <table width="100%" border="0" cellspacing="0" cellpadding="0">\n   ...
## ...

It's likely the table you need is in there.

For others (since this code works for this site) you may also need to pipe your own data to iconv() to deal with other encoding issues.



来源:https://stackoverflow.com/questions/41138052/r-scraping-aspx-web-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!