Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1928268
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:57:28+00:00 2026-05-17T06:57:28+00:00

The two posts below are great examples of different approaches of extracting data from

  • 0

The two posts below are great examples of different approaches of extracting data from websites and parsing it into R.

Scraping html tables into R data frames using the XML package

How can I use R (Rcurl/XML packages ?!) to scrape this webpage

I am very new to programming, and am just starting out with R, so I am hoping this question is pretty basic, but given those posts above, I imagine that it is.

All I am looking to do is extract links that match a given pattern. I feel like I could probably use RCurl to read in the web pages and extract them brute force method using string expressions. That said, if the webpage is fairly well formed, how would I go about doing so using the XML package.

As I learn more, I like to “look” at the data as I work through the problem. The issue is that some of these approaches generate lists of lists of lists, etc., so it is hard for someone that is new (like me) to walk through where I need to go.

Again, I am very new to all that is programming, so any help or code snippets will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:57:28+00:00Added an answer on May 17, 2026 at 6:57 am

    The documentation for htmlTreeParse shows one method. Here’s another:

    > url <- "http://stackoverflow.com/questions/3746256/extract-links-from-webpage-using-r"
    > doc <- htmlParse(url)
    > links <- xpathSApply(doc, "//a/@href")
    > free(doc)
    

    (You can drop the “href” attribute from the returned links by passing “links” through “as.vector”.)

    My previous reply:

    One approach is to use Hadley Wickham’s stringr package, which you can install with install.packages(“stringr”, dep=TRUE).

    > url <- "http://stackoverflow.com/questions/3746256/extract-links-from-webpage-using-r"
    > html <- paste(readLines(url), collapse="\n")
    > library(stringr)
    > matched <- str_match_all(html, "<a href=\"(.*?)\"")
    

    (I guess some people might not approve of using regexp’s here.)

    matched is a list of matrixes, one per input string in the vector html — since that has length one here, matched just has one element. The matches for the first capture group are in column 2 of this matrix (and in general, the ith group would appear in column (i + 1)).

    > links <- matched[[1]][, 2]
    > head(links)
    [1] "/users/login?returnurl=%2fquestions%2f3746256%2fextract-links-from-webpage-using-r"
    [2] "http://careers.stackoverflow.com"                                                  
    [3] "http://meta.stackoverflow.com"                                                     
    [4] "/about"                                                                            
    [5] "/faq"                                                                              
    [6] "/"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not the first to have these issues, and will list some reference posts
I'm trying to calculate the distance between two places user Core Location. I've found
This is a two-part question about adding a third-party library (JAR) to an Android
I'm revising my question from a few days ago. Rewrote my query. Can someone
I asked the question below couple of weeks ago. Now, when reviewing my question
What is wrong with this Smarty php templating code? If I include either of
I installed IronPython 2.6.1 on Windows Vista x64 on a machine with Visual Studio
I have a windows forms application and which provides a way to search the
This post is related to my Previous Post . There I was creating the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.