Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在编译数据时,当网页抓取时缺少值时该怎么办?_R_Database_Web Scraping - Fatal编程技术网

R 在编译数据时,当网页抓取时缺少值时该怎么办?

R 在编译数据时,当网页抓取时缺少值时该怎么办?,r,database,web-scraping,R,Database,Web Scraping,我有几个问题 我正在从一本杂志上抓取数据,并试图将其编译成一个数据集。我在编译时遇到的问题是,我正在抓取的一些html对象的空值 page1<-read_html("http://journals.sagepub.com/doi/full/10.3102/0013189X08317501") author <- html_text(html_nodes(page1, '.art_authors')) year <- html_text(html_nodes(page1, '.y

我有几个问题

我正在从一本杂志上抓取数据,并试图将其编译成一个数据集。我在编译时遇到的问题是,我正在抓取的一些html对象的空值

page1<-read_html("http://journals.sagepub.com/doi/full/10.3102/0013189X08317501")
author <- html_text(html_nodes(page1, '.art_authors'))
year <- html_text(html_nodes(page1, '.year'))
journalName <- html_text(html_nodes(page1, '.journalName'))
art_title <- html_text(html_nodes(page1, '.art_title'))
volume <- html_text(html_nodes(page1, '.volume'))
page <- html_text(html_nodes(page1, '.page'))
email <- html_text(html_nodes(page1, xpath = "//a[@class = 'email']"))
row1<-cbind(author, year, journalName, art_title, volume, page, email)

page2<-read_html("http://journals.sagepub.com/doi/abs/10.3102/0013189X037002102")
author <- html_text(html_nodes(page2, '.art_authors'))
year <- html_text(html_nodes(page2, '.year'))
journalName <- html_text(html_nodes(page2, '.journalName'))
art_title <- html_text(html_nodes(page2, '.art_title'))
volume <- html_text(html_nodes(page2, '.volume'))
page <- html_text(html_nodes(page2, '.page'))
email <- html_text(html_nodes(page2, xpath = "//a[@class = 'email']"))
row2<-cbind(author, year, journalName, art_title, volume, page, email)

page3<-read_html("http://journals.sagepub.com/doi/abs/10.3102/0013189X037002104")
author <- html_text(html_nodes(page3, '.art_authors'))
year <- html_text(html_nodes(page3, '.year'))
journalName <- html_text(html_nodes(page3, '.journalName'))
art_title <- html_text(html_nodes(page3, '.art_title'))
volume <- html_text(html_nodes(page3, '.volume'))
page <- html_text(html_nodes(page3, '.page'))
email <- html_text(html_nodes(page3, xpath = "//a[@class = 'email']"))
row3<-cbind(author, year, journalName, art_title, volume, page, email)
View (row3)

a <- rbind (row1, row2, row3)

page1对于问题的第一部分,您可以只为每个刮削节点编写一个if-else条件,以便在缺少字段的情况下指定一个默认值


此外,您可以不单独调用这三个页面,而是将所有URL保存在一个列表中,循环列表的长度,并将其保存到循环中的数据框中。

这绝对是一个编程问题@g5wOP:answes有几十个类似的问题,哪些问题没有帮助?
pagex<-read_html("http://journals.sagepub.com/doi/full/xxxx/xxxxxxx")