Construir um sistema de números autônomos raspador web / como extrair números de um arquivo de texto

estou a tentar construir um scrapper web com javascript usando pacotes de nó para obter dados de prefixo asn deste site: http://bgp.he.net/AS2#_prefixes .

Isto é o que tenho até agora.
var request = require('request');
var cheerio = require('cheerio');

apnList = {
    'MIT': 3,
    'Dynamics': 15,
    'NYU': 12,
    'Harvard': 11,
    'Bull HN Information Sys': 6,
    'NNIC': 22,
    'Symbolics': 5,
    'University of Delaware': 2
};
for (apn in apnList) {
    var url = 'http://bgp.he.net/AS'+apnList[apn]+'#_prefixes'


    request(url,  (function(apn) { return function(err, resp, body) {
        $ = cheerio.load(body);
        console.log(body) 

    }})(apn));
}
Quando corro o ficheiro no terminal, recebo isto:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /AS11
on this server.</p>
<hr>
<address>Apache/2.2.22 (Ubuntu) Server at bgp.he.net Port 80</address>
</body></html>

para cada número. Como é que eu resolvo isso?

também, questão de bónus: no final, quero pegar em todos os números asn deste ficheiro txt e introduzi-los no loop for.

[asn.txt]                                        2014-06-30 02:05:03Z

This file contains a list of autonomous system numbers and names of all
registered ASNs.  The column on the right below contains the ARIN
database "handle" of the technical, abuse or NOC contacts for the ASN.
Additional information may be obtained about any of the ASN contacts
in this list by querying the ARIN WHOIS server.  For questions or updates
on this information please contact the ARIN Registration Services Hostmaster
staff, [email protected].

AS Number               AS Name                                            POC Handles
 0                       IANA-RSVD-0                                        IANA-IP-ARIN (Abuse), IANA-ARIN (Admin), IANA-IP-ARIN (Tech)
 1                       LVLT-1                                             IPADD5-ARIN (Tech), APL8-ARIN (Abuse), NOCSU27-ARIN (NOC), APL7-ARIN (Admin)
 2                       UDEL-DCN                                           CASHJ-ARIN (Tech), NSS13-ARIN (Abuse), DJG2-ARIN (Tech), DJG2-ARIN (Admin)
 3                       MIT-GATEWAYS                                       MNO78-ARIN (NOC), SILIS-ARIN (Admin), MNS18-ARIN (Abuse), SILIS-ARIN (Tech)
 4                       ISI-AS                                             ACT-ORG-ARIN (Admin), ACT-ORG-ARIN (Abuse), ACT-ORG-ARIN (Tech)
 5                       SYMBOLICS                                          SG52-ARIN (Tech), SG52-ARIN (Admin), SG52-ARIN (Abuse)
 6                       BULL-HN                                            USINT-ARIN (Admin), ZB126-ARIN (Abuse), ZB126-ARIN (Tech), JLM23-ARIN (Tech)
 7                       RIPE-ASNBLOCK-7                                    ABUSE3850-ARIN (Abuse), RNO29-ARIN (Tech), RNO29-ARIN (Admin)
 8                       RICE-AS                                            RUH-ORG-ARIN (Tech), RUH-ORG-ARIN (Admin), RUH-ORG-ARIN (Abuse)
 9                       CMU-ROUTER                                         CH4-ORG-ARIN (Tech), CH4-ORG-ARIN (NOC), CMA3-ARIN (Abuse), CH4-ORG-ARIN (Admin)
 10                      CSNET-EXT-AS                                       CS15-ARIN (Abuse), CS15-ARIN (Tech), CS15-ARIN (Admin)
 11                      HARVARD                                            JNL17-ARIN (Admin), JNL17-ARIN (Tech
Isso foi só uma ... um pedaço dela. Continua por muitos milhares de números. Existe de qualquer forma para extrair seletivamente cada número da coluna de números como?

Author: user3754317, 2014-07-03

2 answers

Parece que ... bgp.he.net blocks tenta raspar seu site, possivelmente baseado em agente de usuário. É por isso que você está recebendo o erro 403: o acesso é negado! Você poderia tentar mudar o agente de usuário que nó.js usa quando recupera URLs remotos( não sei como fazer isso offhand embora), mas parece que Hurricane Electric não é um fã de raspagem, então você provavelmente deve evitá-lo.
 0
Author: D. Strout, 2014-07-24 04:08:58
Esqueci-me de voltar e responder a isto.
var request = require('request');
var cheerio = require('cheerio');
var fs= require('fs')
var filename="/scraping/asn.txt "

apnList = {
    'MIT': 3,
    'Dynamics': 15,
    'NYU': 12,
    'Harvard': 11,
    'Bull HN Information Sys': 6,
    'NNIC': 22,
    'Symbolics': 5,
    'University of Delaware': 2
};
for (apn in apnList) {
    var options = {
        url : 'http://bgp.he.net/AS'+apnList[apn]+'#_prefixes',
        headers:  {
            'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36'
        }
    };


    request(options,  (function(apn) { return function(err, resp, body) {
        var $ = cheerio.load(body);
        $('#table_prefixes4 tr').each(function(index, prefix) {

            $(this).find('.nowrap').each(function(){
            event = $(this).text().trim();
            nextevent = $(this).next().text();
            console.log(apn+","+event+","+nextevent)
            });        
        });


    }})(apn));
}
 0
Author: user3754317, 2014-07-24 15:57:46