作者ya32347844 (虚虚乐)
看板R_Language
标题[问题] 爬虫抓取资料问题
时间Fri Mar 17 00:02:34 2017
[问题类型]:网路爬虫
[软体熟悉度]:入门
[问题叙述]:
我想要抓这个网页的资料 但不知道是不是Xpath写错了 我到後来抓到的资料是NULL
恳请各位大神给予指教 如果有需要补充的资讯也请不吝指出
已经google过相关讯息 用不同的package但结果相同 所以才会觉得是不是一层一层的Tag
写错了
Update Code:
myheader <- c(
"User-Agent"="Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7",
"Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language"="en-us",
"Connection"="keep-alive",
"Accept-Charset"="GB2312,utf-8;q=0.7,*;q=0.7"
)
#加上myheader
d <- debugGatherer()
get_url <- getURL(url, httpheader = myheader, debugfunction = d$update, verbose = T)
get_url_parse = htmlTreeParse(get_url, encoding = "UTF-8", error=function(...){}, useInternalNodes = TRUE,trim=TRUE)
cat(d$value()[3])
node<-getNodeSet(get_url_parse, "//div[@class='page-content-wrapper']")
info<-sapply(node,xmlValue)
info
[程式范例]:
library(XML)
library(RCurl)
url="https://www.eex.com/en/market-data/environmental-markets/spot-market/european-emission-allowances#!/2017/01/04"
get_url = getURL(url,encoding = "UTF-8")
#将url解析
get_url_parse = htmlParse(get_url, encoding = "UTF-8")
tablehead <- xpathSApply(get_url_parse, "//div[@id='content']/section[@class='clearfix']/article[@id='market_data']/div[@id='content']/div/div/div/div",xmlValue)
[环境叙述]:
mac10.12.2
[关键字]:
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.36.131.182
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1489680159.A.038.html
1F:→ celestialgod: 稍微看了一下 这个不好爬XDD 03/17 00:25
2F:→ celestialgod: 看了一下网站 他好像有FTP可以下载资料 03/17 00:25
3F:→ celestialgod: 登入找找相关资讯吧 03/17 00:25
4F:→ celestialgod: 我後来再研究了一下 这网站要把爬虫假装成 03/18 17:50
5F:→ celestialgod: 浏览器行为去爬,需要加一些header即可 03/18 17:51
6F:→ celestialgod: 关键字:keep-live connection 爬虫 03/18 17:51
7F:→ celestialgod: /a 03/18 17:51
8F:→ ya32347844: 感谢!我先研究一下keep-live connection怎麽用 03/18 22:05
※ 编辑: ya32347844 (114.36.131.182), 03/18/2017 23:44:44
9F:→ ya32347844: 更新文章的Code但发现好像还是不行QQ这样有伪装到吗 03/18 23:46