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 8196481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:29:34+00:00 2026-06-07T05:29:34+00:00

I have to scrape a website and save all pages as HTML and put

  • 0

I have to scrape a website and save all pages as HTML and put it entirely on a DVD. I’ve done this, but now all the links start with a /, and that grabs my root directory. I would like to change all hrefs of all files (1500 pages) to href="./" so it always grabs the working directory.

I’ve seen things about sed in bash, but I didn’t quite catch how to dynamically grab all hrefs and change them.

How could I do this in an efficient way?

  • 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-06-07T05:29:35+00:00Added an answer on June 7, 2026 at 5:29 am

    As I said in my comment above, depending on which tool you’re using to scrape the site, you could start with checking whether it supports rewriting links. wget will let you do exactly this by passing the -k option:

    -k,  --convert-links      make links in downloaded HTML or CSS point to
                              local files.
    

    I don’t think Ugo Méda’s suggestion, the base tag, will work, since your URLs are absolute, and the base tag only lets you specify a base for relative URLs:

    href = uri [CT]
    This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.
    

    To rewrite every href is tricky, since it’s so hard to know you’re doing the right thing — it depends on the structure of the site. Consider the following example:

    /foo/bar.html:

    <a href="/bar/baz.html">baz</a>
    

    If you rewrite that per your suggestion, it will be:

    <a href="./bar/baz.html">baz</a>
    

    But that won’t work, since the browser will resolve that to /foo/bar/baz.html, when the file is really at [SOME DIR]/bar/baz.html. In that case, you really want:

    <a href="../bar/baz.html">baz</a>
    

    What I’m trying to say is that the correct (rewritten) URL is always depending on the location of the current file and the location of the target file. In summary, I think your best bet is using wget or some other tool which supports URL rewriting, or you will need some more advanced program than just sed, which lacks the context needed to correctly convert the link.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To save time Googling my website in order to see where my pages have
I'm trying to scrape the price field from this website using the HTML Agility
I need to update the pages from my website to all have the same
I need to crawl a website, which basically has links like this: www.website.com/link/page_1.html www.website.com/link/page_2.html
I have a website that contains many different pages of products and each page
I scrape some sites that occasionally have UTF-8 characters in the title, but that
Dear all,I am now using a webtool http://fiddesktop.cs.northwestern.edu/mmp/scrape?url= to parse a webpage. For example,we
I have a task where I need to autologin and scrape a particualr website.
I have a Mechanize based Ruby script to scrape a website. I am hoping
I have been using readLines() to scrape information from a website in an R

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.