How to loop through all HTML files with R









up vote
-1
down vote

favorite












my current code is like this:



library("rvest")
html <- read_html( "Path/myFile")
arq <- dir(path = 'Path', pattern = "name of the file.htm*",full.names
= FALSE)

###### make tables with html files

table <- html %>%
html_nodes('.list') %>%
# .[[8]] %>%
html_table(fill = TRUE)


###### add html files to a big table called big_data

files; function(x)

big_data <- do.call(rbind, teste_em_tabela, quote = TRUE)




The code above works with one file but I would like to make the code work with all html files in my folder.



My doubt is how to loop in all html files inside a selected folder and insert into a table. (which, in this case, is called big_data).



I've tried to make use of for loops and lapply but I had some problems, specially with Error in UseMethod("read_xml").










share|improve this question



















  • 1




    What answers on SO that are super-related to this did you research and find unhelpfu? (this is a solved problem) I mean, you did do that before asking others to spend time on this, right?
    – hrbrmstr
    Nov 9 at 18:03











  • Yes, i have tried to search for a simple loop inside files on a folder then i searched a more specific question to know how to use rvest to read html files and finally i searched how to deal with the UseMethod error. I'm newbie and i read other webpages as well, really sorry if it's an obvious question or easy to search at SO. I tried to implement the solutions that i saw but i've got stucked.
    – Petrulli
    Nov 9 at 18:18














up vote
-1
down vote

favorite












my current code is like this:



library("rvest")
html <- read_html( "Path/myFile")
arq <- dir(path = 'Path', pattern = "name of the file.htm*",full.names
= FALSE)

###### make tables with html files

table <- html %>%
html_nodes('.list') %>%
# .[[8]] %>%
html_table(fill = TRUE)


###### add html files to a big table called big_data

files; function(x)

big_data <- do.call(rbind, teste_em_tabela, quote = TRUE)




The code above works with one file but I would like to make the code work with all html files in my folder.



My doubt is how to loop in all html files inside a selected folder and insert into a table. (which, in this case, is called big_data).



I've tried to make use of for loops and lapply but I had some problems, specially with Error in UseMethod("read_xml").










share|improve this question



















  • 1




    What answers on SO that are super-related to this did you research and find unhelpfu? (this is a solved problem) I mean, you did do that before asking others to spend time on this, right?
    – hrbrmstr
    Nov 9 at 18:03











  • Yes, i have tried to search for a simple loop inside files on a folder then i searched a more specific question to know how to use rvest to read html files and finally i searched how to deal with the UseMethod error. I'm newbie and i read other webpages as well, really sorry if it's an obvious question or easy to search at SO. I tried to implement the solutions that i saw but i've got stucked.
    – Petrulli
    Nov 9 at 18:18












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











my current code is like this:



library("rvest")
html <- read_html( "Path/myFile")
arq <- dir(path = 'Path', pattern = "name of the file.htm*",full.names
= FALSE)

###### make tables with html files

table <- html %>%
html_nodes('.list') %>%
# .[[8]] %>%
html_table(fill = TRUE)


###### add html files to a big table called big_data

files; function(x)

big_data <- do.call(rbind, teste_em_tabela, quote = TRUE)




The code above works with one file but I would like to make the code work with all html files in my folder.



My doubt is how to loop in all html files inside a selected folder and insert into a table. (which, in this case, is called big_data).



I've tried to make use of for loops and lapply but I had some problems, specially with Error in UseMethod("read_xml").










share|improve this question















my current code is like this:



library("rvest")
html <- read_html( "Path/myFile")
arq <- dir(path = 'Path', pattern = "name of the file.htm*",full.names
= FALSE)

###### make tables with html files

table <- html %>%
html_nodes('.list') %>%
# .[[8]] %>%
html_table(fill = TRUE)


###### add html files to a big table called big_data

files; function(x)

big_data <- do.call(rbind, teste_em_tabela, quote = TRUE)




The code above works with one file but I would like to make the code work with all html files in my folder.



My doubt is how to loop in all html files inside a selected folder and insert into a table. (which, in this case, is called big_data).



I've tried to make use of for loops and lapply but I had some problems, specially with Error in UseMethod("read_xml").







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 18:03









G5W

20.6k82041




20.6k82041










asked Nov 9 at 18:00









Petrulli

13




13







  • 1




    What answers on SO that are super-related to this did you research and find unhelpfu? (this is a solved problem) I mean, you did do that before asking others to spend time on this, right?
    – hrbrmstr
    Nov 9 at 18:03











  • Yes, i have tried to search for a simple loop inside files on a folder then i searched a more specific question to know how to use rvest to read html files and finally i searched how to deal with the UseMethod error. I'm newbie and i read other webpages as well, really sorry if it's an obvious question or easy to search at SO. I tried to implement the solutions that i saw but i've got stucked.
    – Petrulli
    Nov 9 at 18:18












  • 1




    What answers on SO that are super-related to this did you research and find unhelpfu? (this is a solved problem) I mean, you did do that before asking others to spend time on this, right?
    – hrbrmstr
    Nov 9 at 18:03











  • Yes, i have tried to search for a simple loop inside files on a folder then i searched a more specific question to know how to use rvest to read html files and finally i searched how to deal with the UseMethod error. I'm newbie and i read other webpages as well, really sorry if it's an obvious question or easy to search at SO. I tried to implement the solutions that i saw but i've got stucked.
    – Petrulli
    Nov 9 at 18:18







1




1




What answers on SO that are super-related to this did you research and find unhelpfu? (this is a solved problem) I mean, you did do that before asking others to spend time on this, right?
– hrbrmstr
Nov 9 at 18:03





What answers on SO that are super-related to this did you research and find unhelpfu? (this is a solved problem) I mean, you did do that before asking others to spend time on this, right?
– hrbrmstr
Nov 9 at 18:03













Yes, i have tried to search for a simple loop inside files on a folder then i searched a more specific question to know how to use rvest to read html files and finally i searched how to deal with the UseMethod error. I'm newbie and i read other webpages as well, really sorry if it's an obvious question or easy to search at SO. I tried to implement the solutions that i saw but i've got stucked.
– Petrulli
Nov 9 at 18:18




Yes, i have tried to search for a simple loop inside files on a folder then i searched a more specific question to know how to use rvest to read html files and finally i searched how to deal with the UseMethod error. I'm newbie and i read other webpages as well, really sorry if it's an obvious question or easy to search at SO. I tried to implement the solutions that i saw but i've got stucked.
– Petrulli
Nov 9 at 18:18

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231084%2fhow-to-loop-through-all-html-files-with-r%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231084%2fhow-to-loop-through-all-html-files-with-r%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo