I am working on Rvest for web scraping. I have collected the list of outputs from the page but my functions fails to wrap it in dataframe. My code:
test_qry <- lapply(paste0('https://......&CurrentPage=', 1:3),
function(url){
c(
hospital <- url %>% read_html() %>%
html_nodes(".findcompare-results table th.fctitle a") %>%
html_text(),
Tele_no <- url %>% read_html() %>%
html_nodes(".findcompare-results table td p.fctel") %>%
html_text())
})
I dont know how to create dataframe inside the function to wrap all the variables. I used this function to read all the pages(totally 3 pages). My output is like this
1 Coulsdon Dental Practice
2 mydentist, Chipstead Valley Road, Coulsdon
3 Coulsdon Dental Clinic
4 Ivory
5 Crossways Dental Practice
6 Confidental Clinic
7 Azenabor, Ify
8 Kerschbaumer, Andreas
9 Paice, Andrew
10 Kenley Dental Practice
11 Tel: 020 8668 2607
12 Tel: 02086686870
13 Tel: 020 8660 3308
14 Tel: 020 8668 2579
15 Tel: 01737 551622
16 Tel: 020 8660 8923
17 Tel: 01737 554177
18 Tel: 020 8660 0415
19 Tel: 020 8660 6565
20 Tel: 020 8668 2696
But I need two seperate variables, it writes to single list. Like data.frame(name,tele_no)
I have used unlist(test_qry) to create data frame.
Help me please!!!