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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:43:31+00:00 2026-06-13T04:43:31+00:00

I’m developing a program that scrapes content from various online archives, but am new

  • 0

I’m developing a program that scrapes content from various online archives, but am new to OOP. The way I believe would work best would be to have a parent class that specifies the shared variables and methods, then a child class for each archive which then contains the specific methods for grabbing info from that particular site, such as GrabStoryVariables() existing in each child class to accommodate the individual needs of that archive. The program takes a URL in a textbox, and then from there it will determine using the URL which child class to instantiate.

The problem I’m having is figuring out how to create the child class object and make it accessible to the entire program. For example, to create an instance of FanFictionAuthors : FanBook:

private void btnGetInfo(object sender, EventArgs e)
{
  CreateBook();
}

private void CreateBook()
{
  if (addressBar.Text.Contains("fanficauthors.net"))
  {
    FanFictionAuthors myBook = new FanFictionAuthors();
  }
  return;
}

The scope of myBook is just the CreateBook() function, so this approach won’t do the trick. Any suggestions on the best way to handle this issue? I’m using this as an approach to better learn programming, so the “correct” way is what I’m trying to figure out, whatever that is.

Edit: The specific function of the program is to take a provided URL for an online story from fanfiction.net, fictionpress.com, or one of any number of other online story archives. There are a set of shared attributes each story will have, such as title, number of chapters, length in words, chapter titles, and the actual content of the story. The program compiles all of this to create a single html document (later to be expanded to allow for different ebook formats) rather than a bunch of small individual chapter files.

With that in mind, the only parts that should differ between each archive are the methods for grabbing the variables from the particular archive and how to iterate between the chapters based on the archive’s function for that.

Currently what I’m doing is just creating a myBook object immediately upon launching the main form, then creating a different method name for the functions that grab the variables and do the iteration. As I add more archives, however, this becomes more complicated. What I originally wanted to do was to just cast the myBook to the individual archive types (FanFictionAuthors in this case) to grab the ability to use their specific functions. Looking online, it appears casting from parent to child isn’t easy nor recommended, so I’m not sure how else to approach this.

Here’s the GitHub link for the project. This version is slightly out of date, but lets you see how I’m currently approaching this: https://github.com/benroth/fBook

  • 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-13T04:43:32+00:00Added an answer on June 13, 2026 at 4:43 am

    Create a super class where you common attributes and methods in there:

    public class FanBook
    {
        // use a common constructor
        public FanBook(string url)
        {
            grabHtml(url);
            // ...
        }
    
        protected string grabHtml(string address) { // SNIP }
    
        protected void CreateStoryHeader() { // SNIP }
    
        // other common methods which are the same for every subclass (maybe BuildToc, GetStory, etc.)
    
        // maybe if you want some easy access to attributes, you could add a dictionary
        public void Dictionary<string, string> Attributes;
    
        // Then use abstract methods to define methods that are different for subclasses
        protected abstract void GrabStoryVariables();
        protected abstract void GenerateStoryInfo();
    }
    

    Then create a subclass that derives from Book:

    public class FFNETBook : FanBook {
        // FFNETBook constructor to call contructor from FanBook too
        public FFNETBook(string url) : FanBook(url) {
            // specific initializations for FFNET
    
        }
    
        public override void GrabStoryVariables() { // special implementation for FFNET here }
    
        public override void GenerateStoryInfo() { // special implementation for FFNET here }
    }
    

    I know OOP is hard to grasp when you don’t have much experience in it. So feel free to ask questions.
    If you do it right, then you would never need to cast into subclasses.

    To answer the question in the comment:

    You could make a class variable in the form1.cs file:

    private FanBook currentBook;
    
    private void CreateBook()
    {
        currentBook = new FFNETFanBook("http://...");
    }
    
    private void AnotherMethod() {
        if ( currentBook != null ) {
            currentBook.GrabStoryVariables();
        } else {
            throw new Exception("Book not initialized yet.");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.