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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:29:17+00:00 2026-06-17T09:29:17+00:00

So I need to save several links from a site, but when it reaches

  • 0

So I need to save several links from a site, but when it reaches near the 64k links it gives me the error OutOfMemoryException.

Here is my code, please if someone could help me it would be wonderful.

Note : if you want to test (of course you have to edit to test, but it is not that much to edit), the url it receives is :

http://santacatarina.entrei.net/busca/listar_empresas.php?filter={0}&pagina={1}

The code :

namespace WebCrawler.SantaCatarina
{

class SCLinkFinder : ILinkFinder

{

private readonly Queue<char> _alfabeto;
private int _paginaAtual;
private char _letraAtual;

public SCLinkFinder()
{
    _alfabeto = new Queue<char>();
    _alfabeto.Enqueue('1');
    _alfabeto.Enqueue('A');
    _alfabeto.Enqueue('B');
    _alfabeto.Enqueue('C');
    _alfabeto.Enqueue('D');
    _alfabeto.Enqueue('E');
    _alfabeto.Enqueue('F');
    _alfabeto.Enqueue('G');
    _alfabeto.Enqueue('H');
    _alfabeto.Enqueue('I');
    _alfabeto.Enqueue('J');
    _alfabeto.Enqueue('K');
    _alfabeto.Enqueue('L');
    _alfabeto.Enqueue('M');
    _alfabeto.Enqueue('N');
    _alfabeto.Enqueue('O');
    _alfabeto.Enqueue('P');
    _alfabeto.Enqueue('Q');
    _alfabeto.Enqueue('R');
    _alfabeto.Enqueue('S');
    _alfabeto.Enqueue('T');
    _alfabeto.Enqueue('U');
    _alfabeto.Enqueue('V');
    _alfabeto.Enqueue('W');
    _alfabeto.Enqueue('X');
    _alfabeto.Enqueue('Y');
    _alfabeto.Enqueue('Z');

    _paginaAtual = 1;
    _letraAtual = _alfabeto.Dequeue();
}

public string[] Find(string url)
{
    List<string> _empresas = new List<string>();

    if (!_alfabeto.Any() && _letraAtual == ' ')
    {
        return _empresas.ToArray();
    }
    var webGet = new HtmlWeb();
    var formattedUrl = String.Format(url, _letraAtual, _paginaAtual++);
    var document = webGet.Load(formattedUrl);
    var nodes = document.DocumentNode.SelectNodes("//div[@id='conteudo']/div[@class='gratuito']/p/a");

    foreach (var node in nodes)
    {
        var href = node.GetAttributeValue("href", "");
        _empresas.Add(href);
    }

    var elUrlProximaPagina = document.DocumentNode.SelectSingleNode("//div[@id='principal']/div[@id='conteudo']/div[@class='paginacao']/a[contains(@class,'nextPage')]");
    if (elUrlProximaPagina == null)
    {
        _letraAtual = _alfabeto.Any() ? _alfabeto.Dequeue() : ' ';
        _paginaAtual = 1;
    }
    Console.WriteLine(_letraAtual);
    Console.WriteLine(_paginaAtual);

    DadoPo.SalvarUrl();         

    return Find(url);
}

}

Ok, now the error is at another place, it is giving outofmemoryexception at
var document = webGet.Load(formattedUrl);

  • 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-17T09:29:18+00:00Added an answer on June 17, 2026 at 9:29 am

    Persist the content of _empresas in the harddisk (database, physical file) after N times(1,000 for example) of scraped information from the website. And then clean the _empresas for a new set of information

    What you are doing is pretty much using all the memory allowed by CLR for your PE

    namespace WebCrawler.SantaCatarina
    {
    class SCLinkFinder : ILinkFinder
    {
        private readonly Queue<char> _alfabeto;
    
        private int _paginaAtual;
        private char _letraAtual;
    
        public SCLinkFinder()
        {
            _alfabeto = new Queue<char>();
            _alfabeto.Enqueue('1');
            _alfabeto.Enqueue('A');
            _alfabeto.Enqueue('B');
            _alfabeto.Enqueue('C');
            _alfabeto.Enqueue('D');
            _alfabeto.Enqueue('E');
            _alfabeto.Enqueue('F');
            _alfabeto.Enqueue('G');
            _alfabeto.Enqueue('H');
            _alfabeto.Enqueue('I');
            _alfabeto.Enqueue('J');
            _alfabeto.Enqueue('K');
            _alfabeto.Enqueue('L');
            _alfabeto.Enqueue('M');
            _alfabeto.Enqueue('N');
            _alfabeto.Enqueue('O');
            _alfabeto.Enqueue('P');
            _alfabeto.Enqueue('Q');
            _alfabeto.Enqueue('R');
            _alfabeto.Enqueue('S');
            _alfabeto.Enqueue('T');
            _alfabeto.Enqueue('U');
            _alfabeto.Enqueue('V');
            _alfabeto.Enqueue('W');
            _alfabeto.Enqueue('X');
            _alfabeto.Enqueue('Y');
            _alfabeto.Enqueue('Z');
    
            _paginaAtual = 1;
            _letraAtual = _alfabeto.Dequeue();
        }
    
        public string[] Find(string url)
        {
            List<string> _empresas = new List<string>();
    
            if (!_alfabeto.Any() && _letraAtual == ' ')
            {
                return _empresas.ToArray();
            }
            var webGet = new HtmlWeb();
            var formattedUrl = String.Format(url, _letraAtual, _paginaAtual++);
            var document = webGet.Load(formattedUrl);
            var nodes = document.DocumentNode.SelectNodes("//div[@id='conteudo']/div[@class='gratuito']/p/a");
    
            foreach (var node in nodes)
            {
                var href = node.GetAttributeValue("href", "");
                _empresas.Add(href);
            }
    
            var elUrlProximaPagina = document.DocumentNode.SelectSingleNode("//div[@id='principal']/div[@id='conteudo']/div[@class='paginacao']/a[contains(@class,'nextPage')]");
            if (elUrlProximaPagina == null)
            {
                _letraAtual = _alfabeto.Any() ? _alfabeto.Dequeue() : ' ';
                _paginaAtual = 1;
            }
            Console.WriteLine(_letraAtual);
            Console.WriteLine(_paginaAtual);
    
            //Your code to read _empresas and Persist in database(or file)            
    
            return Find(url);
        }
    }
    

    }

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

Sidebar

Related Questions

I need to save an camera image from my application to the desktop so
I need to save the field value several times by separating them by commas.
I need to get the complete output from an aspx site. When the user
I'm writing an app that loads several images from a server, and I need
.txt file need save in SD-card. Save(n + String.valueOf(key) + .txt); private void Save(String
(sorry for my english) I need save an image in the application path and
I need to save to an isolated storage the total time that the user
I need to save the context of the program before exiting ... I've put
I need to save some classes and data structures to a file. My first
I need to save images in certain folder of my application: string path=E:\AJAXEnabledWebSite1\images\gallery 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.