[问题] 爬虫问题

楼主: cd12631 (<(◥█◤△◥█◤)>)   2017-06-14 23:39:40
[问题类型]:
程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
[软件熟悉度]:
使用者(已经有用R 做过不少作品)
[问题叙述]:
平常是很少爬虫 之前有在爬的时候也算是顺利
今天临时把之前爬过的东西翻出来要抓资料
网页如下:
http://ntpc.youbike.com.tw/cht/f12.php?loc=taipei
但之前爬得很顺利的东西(两年前)
今天突然抓不下来
爬文以及google一下 似乎是Keep-Alive Connection的问题
也许这两年内这网站加上这东西
google了一下相关的资讯还是无法爬成功
只好上来请教各位先进
[程式范例]:
library(magrittr)
library(httr)
library(rvest)
library(stringr)
# 例如我要抓这网页可停空位那一栏
ubikeurl <- "http://ntpc.youbike.com.tw/cht/f12.php?loc=taipei"
urlubike <- read_html(ubikeurl)
ubike <- urlubike %>%
html_nodes(., xpath = "//tr/td[4]") %>%
html_text
[环境叙述]:
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
[关键字]:
选择性,也许未来有用
作者: max6 (啊囉哈)   2017-07-02 12:44:00
那个table是用javascript生成的,所以直接download html是看不到的。你可以用Selenium开Browser去抓。或是读他的原始码看那个table怎么生成的。目前看起来是javascript有一个变量arealist, urldecode再parse json后就是你到的东西,注意他的中文是用unicode显示

Links booklink

Contact Us: admin [ a t ] ucptt.com