作者cd12631 (<(◥█◤△◥█◤)>)
看板R_Language
标题[问题] 爬虫问题
时间Wed Jun 14 23:39:40 2017
[问题类型]:
程式谘询(我想用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)
[关键字]:
选择性,也许未来有用
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.34.124.238
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1497454783.A.636.html
※ 编辑: cd12631 (1.34.124.238), 06/14/2017 23:41:01
1F:→ max6: 那个table是用javascript生成的,所以直接download html是 07/02 12:44
2F:→ max6: 看不到的。你可以用Selenium开Browser去抓。或是读他的原始 07/02 12:45
3F:→ max6: 码看那个table怎麽生成的。目前看起来是javascript有一个变 07/02 12:48
4F:→ max6: 数arealist, urldecode再parse json後就是你到的东西,注意 07/02 12:49
5F:→ max6: 他的中文是用unicode显示 07/02 12:49