2

I'm scraping a website and getting 404 error. I use tryCatch() but it doesn't work. How can I skip this page/url using it or any method you can suggest?

result = tryCatch(expr = {
  map_dfr(
    .x = url,
    .f = function(x) {
      tibble(
        #expr
      )
    }
  )
  
})

Thanks in advance.

youraz
  • 463
  • 4
  • 14
  • 1
    In the `tryCatch`, you can specify `error` and if it goes into error, which value to return. In the code, I didn't find that part. May be you have tried, not sure? – akrun Mar 20 '21 at 17:38
  • 1
    I think that the more scalable approach is to use `function_safely = purrr::safely(function(etc))` and then use `map_dfr` on `function_safely`. The outcome provides two lists: one for errors and one for results. To select just the working part, call `outcome$result` – p0bs Mar 20 '21 at 17:57
  • I was wondering how I could run tryCatch() method and put error function so, it works! Thanks! @akrun – youraz Mar 20 '21 at 18:58
  • @nerdakgul you may check [here](https://stackoverflow.com/questions/12193779/how-to-write-trycatch-in-r) – akrun Mar 20 '21 at 18:59
  • 1
    I've learned another function. Thanks! @p0bs – youraz Mar 20 '21 at 18:59
  • I thought I would not put this function because it's optional @akrun – youraz Mar 20 '21 at 19:01

0 Answers0