Tag: networking抓取

使用Node.js,请求和cheerio从网站上刮下链接?

我试图使用Node.js,请求和cheerio在我学校的课程安排网站上刮取链接。 但是,我的代码没有达到所有主题链接。 链接到课程安排网站在这里 。 以下是我的代码: var express = require('express'); var request = require('request'); var cheerio = require('cheerio'); var app = express(); app.get('/subjects', function(req, res) { var URL = 'http://courseschedules.njit.edu/index.aspx?semester=2016s'; request(URL, function(error, response, body) { if(!error) { var $ = cheerio.load(body); $('.courseList_section a').each(function() { var text = $(this).text(); var link = $(this).attr('href'); console.log(text + ' –> […]

启动npm时出错?

我是新的Angular2,当我尝试启动npm服务器与npm start项目的文件夹内我得到这些错误 > angular2-authentication-sample@0.0.1 start /home/no-one/Desktop/Frontend > npm run front > angular2-authentication-sample@0.0.1 front /home/no-one/Desktop/Frontend > webpack-dev-server –inline -d –colors –display-error-details –display-cached –port 3000 sh: 1: webpack-dev-server: Permission denied npm ERR! Linux 3.19.0-51-generic npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "front" npm ERR! node v5.6.0 npm ERR! npm v3.7.3 npm ERR! code ELIFECYCLE npm ERR! angular2-authentication-sample@0.0.1 front: […]

如何写HTML结构的cheerio查询?

我的cheerio代码片段如下。 我试图获取<td>标签中的项目名称,并获取后续td标签(1,2,1)中的数字。 itemName查询起作用,但startPrice,endPrice和difPrice查询不起作用。 我的逻辑中的缺陷在哪里?或者是一个句法错误? var $ = cheerio.load(html); // $('.table-item-link').each(function(i, element) { var itemName = ($(this).attr('title'); console.log(itemName); }); //Iterate through all tr inside div = 'content' $('.content tr').each(function(i, element) { var startPrice = $(this).children()[2].children()[0].text(); var endPrice = $(this).children()[3].children()[0].text(); var difPrice = $(this).children()[4].children()[0].text(); console.log(price) }); <div class='content'> <table> <thead> <tr>Table Title</tr> <tbody> <tr> <td> <a href="http://services.runescape.com/m=itemdb_rs/Jangerberry_seed/viewitem?obj=5104" […]

如何使用幻像爬虫将html源代码打印到控制台

我刚刚下载并安装了phantom-crawler for nodejs。 我将以下脚本复制并粘贴到名为crawler.js的文件中: var Crawler = require('phantom-crawler'); // Can be initialized with optional options object var crawler = new Crawler(); // queue is an array of URLs to be crawled crawler.queue.push('https://google.com/'); // Can also do `crawler.fetch(url)` instead of pushing it and crawling it // Extract plainText out of each phantomjs page Promise.all(crawler.crawl()) .then(function(pages) { […]

我应该发送多less个并发http请求?

我需要同时发送大约50或60个请求到远程服务器。 我对networking了解不多。 我刚刚意识到,例如: 发送5次请求10次与发送50次请求完全不同 怎样才能知道同时发送的最高“并发”HTTP请求数量?

Cheerio .css()总是返回null?

我最近开始和Cheerio一起使用NodeJS 。 我得到一个外部URL,并加载与Cheerio的HTML。 我偶然发现了一个问题,每当我试图获取一个元素的CSS属性, $.css([property])总是返回null ,无论我给它什么select器或属性。 我在做什么: var express = require('express'); var fs = require('fs'); var request = require('request'); var cheerio = require('cheerio'); app = express(); app.get('/something_something', function (req, res) { request('some_url', function (error, response, html) { var $ = cheerio.load(html) // console.log($('body').css('width')); } } 无论使用哪种select器或CSS属性,这将始终logging为null 。 (请记住,我已经过度检查了jQuery对象$(“body”)是否存在,并且无论这个URL是什么都会发生) 另外,如果我设置$('body').css('width', '100px') ,然后console.log($('body').css('width')) ,它将显示100px。 所以我猜这不是css()方法本身,但Cheerio获取/不获取元素样式 *其他Cheerio方法的工作,如text() , […]

使用JS将网页的元素保存为图像

我知道这个问题之前已经被问过了,但是所有的答案都是在几年前,所以也许有些改变。 我发现这个https://github.com/apollolm/phantasm ,这正是我所需要的。 但是我在OSX上,似乎不被支持。 那么,我怎样才能使用javascript来保存一个网页partulcar部分的图像?

我怎样才能用Node.js刮页面

我试图刮一个网站,但我不能得到的结果写入到一个HTML文件。 我在node.js中使用了cheerio,我的代码如下所示。 var http = require('http'); var path = require('path'); var request = require('request'); var cheerio = require('cheerio'); http.createServer(function (req, res) { res.write('<html><head></head><body>'); request('http://www.espn.com', function(err, res, html){ var $ = cheerio.load(html); $('a.realStory').each(function(i, element) { var node = $(this); var text = node.text(); res.write('<p>'+ text +'</p>'); }); }); res.end('</body></html>'); }).listen(1337); 我怎样才能运行这个文件,然后到我的本地主机来查看它?

使用casperjs / phantomjslogging到Amazon Developer网页

我有一个问题,试图用CasperJSlogin到亚马逊开发者网页 – 电子邮件和通过成功input,但在“login”button单击,我收到一条消息,input一个有效的电子邮件(和我的电子邮件是有效的 – 我手动成功login)。 试图login到Facebook,它使用了几乎相同的代码。 我使用了这个网站的代码: http : //code-epicenter.com/how-to-login-to-amazon-using-casperjs-working-example/ 谢谢!

通过websocket添加聊天,到现有的PHPnetworking应用程序

我在标准的PHP / Apache平台上有一个现有的Web应用程序。 现在,我想要的是添加聊天function,我希望它是实时的通过websocket,并扩展我已经研究了一点nodeJs上的socket.io。 因此,除了运行大型PHP应用程序的Apache之外,我还会使用socket.io运行聊天的nodejs。 但是我真的不明白的是,如何在nodejs聊天的代码中识别我的用户呢? 首先,Apache和nodejs将无法在同一个端口上运行,这意味着我将在端口8080上运行聊天,例如,在这种情况下,我丢失了用户的cookies,这意味着我现在必须要求他们login再次在这个nodejs-powered端口,如果他们想使用聊天? 看起来很荒谬,但是我不知道要走哪条路。 当然,我无法将我的整个代码移植到nodejs上。 所以理想情况下,我会希望Apache和nodejs共存。 或者我完全误解了聊天应该如何在networking应用程序中工作。 任何提示赞赏。