Comments (4)
Would you use try(expr,silent)
in your last lapply()
? If one URL does not work, try()
will prevent the loop from stopping.
from rvest.
Thanks, I used it as you suggested, but I am still getting the same error:
Warning message:
In request_GET(session, url) : client error: (400) Bad Request
On Fri, Sep 26, 2014 at 7:08 PM, Kun Ren [email protected] wrote:
Would you use try(expr,silent) in your last lapply()? If one URL does not
work, try() will prevent the loop from stopping.—
Reply to this email directly or view it on GitHub
#20 (comment).
from rvest.
Would you try the following:
dfs2 <- lapply(topics, function(src) {
top = rep(paste0(src), times=25)
result <- try({
page <- html_session(paste0(base, src, '.html' ))
list(quote = page %>% html_nodes(xpath='//span[@class="bqQuoteLink"]/a') %>% html_text() %>% .[1:25] ,
author = page %>% html_nodes(xpath='//div[@class="bq-aut"]') %>% html_text() %>% .[1:25],
topic = top[1:25]
)},silent = TRUE)
if(!inherits(result, "try-error")) result
})
from rvest.
This works. Thank you.
On Fri, Sep 26, 2014 at 9:48 PM, Kun Ren [email protected] wrote:
Would you try the following:
dfs2 <- lapply(topics, function(src) {
top = rep(paste0(src), times=25)
result <- try({
page <- html_session(paste0(base, src, '.html' ))
list(quote = page %>% html_nodes(xpath='//span[@Class="bqQuoteLink"]/a') %>% html_text() %>% .[1:25] ,
author = page %>% html_nodes(xpath='//div[@Class="bq-aut"]') %>% html_text() %>% .[1:25],
topic = top[1:25]
)
},silent = TRUE)
if(!inherits(result, "try-error")) result})—
Reply to this email directly or view it on GitHub
#20 (comment).
from rvest.
Related Issues (20)
- Github Actions Can't Install Dev Version HOT 4
- Figure out dynamic html elements selection
- read_html_live() practical implementation HOT 1
- Release rvest 1.0.4
- Long lines truncated at 10,000,000 chars. HOT 4
- Invalid Char in Json Text
- `req_perform_iteratively()` + `paths` HOT 1
- Need absolute URL helper HOT 1
- Web scraping vignette
- LiveHTML object corrupted after `$click()` HOT 1
- read_html should take httr2 response directly
- Hide more automated browser tells
- read_html_live() memory "leak" HOT 4
- Example broken in LiveHTML page HOT 1
- README should end with link to getting started vignette
- Select option from list using htmlLIVE
- Finding elements/nodes in regex way
- Try S7
- Use base pipe in examples
- Draw on examples from https://www.scrapingcourse.com
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rvest.