我正在使用Node和Cheerio构建一个web scraper,对于某个网站,我遇到了以下错误(它只发生在这个网站上,没有其他我试图抓取.
它每次都发生在不同的位置,所以有时它url x
会抛出错误,其他时候url x
很好,它完全是一个不同的URL:
Error!: Error: socket hang up using [insert random URL, it's different every time]
Error: socket hang up
at createHangUpError (http.js:1445:15)
at Socket.socketOnEnd [as onend] (http.js:1541:23)
at Socket.g (events.js:175:14)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:910:16
at process._tickCallback (node.js:415:13)
Run Code Online (Sandbox Code Playgroud)
调试非常棘手,我真的不知道从哪里开始.首先,什么IS插座挂断错误?是404错误还是类似错误?或者它只是意味着服务器拒绝连接?
我无法在任何地方找到解释!
编辑:这是一个(有时)返回错误的代码示例:
function scrapeNexts(url, oncomplete) {
request(url, function(err, resp, body) {
if (err) {
console.log("Uh-oh, ScrapeNexts Error!: " + err + " using " + url);
errors.nexts.push(url);
}
$ = cheerio.load(body);
// …
Run Code Online (Sandbox Code Playgroud) 我正在运行一个简单ng-repeat
的JSON文件,并希望得到类别名称.大约有100个对象,每个对象属于一个类别 - 但只有大约6个类别.
我目前的代码是这样的:
<select ng-model="orderProp" >
<option ng-repeat="place in places" value="{{place.category}}">{{place.category}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
输出是100个不同的选项,大多数是重复的.如何使用Angular检查是否{{place.category}}
已存在,如果已存在则不创建选项?
编辑:在我的javascript中$scope.places = JSON data
,只是为了澄清
我的node.js
应用程序有很多控制台日志,这对我来说很重要(它是一个非常大的应用程序,因此运行了很长时间,我需要知道事情仍在进行中)但我最终会有数千行控制台日志.
是否可能以某种方式console.update
擦除/替换控制台线而不是创建新线?
我知道$ addToSet方法MongoDB
,但我remove
在文档中的任何地方都找不到等价物.
实现这一目标的最佳方法是什么?尝试实现以下内容:
obj = {
name: 'object1
tags: ['fus', 'ro', 'dah']
}
db.collection.update({name: 'object1'}, {$removeFromSet: { tags: 'dah'}});
Run Code Online (Sandbox Code Playgroud) 我正在使用MongoDb
(作为一部分MongoJS
)Node
.这是MongoJS的文档.
我正在尝试根据条目的_id
字段在Node内进行调用.MongoDB
从控制台使用香草时,我可以这样做:
db.products.find({"_id":ObjectId("51d151c6b918a71d170000c7")})
它正确地返回我的条目.但是,当我在Node中做同样的事情时,例如:
db.products.find({"_id": ObjectId("51d151c6b918a71d170000c7")}, function (err, record) {
// Do stuff
});
Run Code Online (Sandbox Code Playgroud)
我得到ReferenceError: ObjectId is not defined
.
这样做的正确协议是什么?
无法在任何地方找到有关此特定错误的任何信息,请耐心等待.
我的Angular/NodeJS应用程序有一个通过Stripe处理的支付页面(用于月度和年度订阅).
我在Stripe仪表板中创建了订阅类型(两个订阅:StarterAnnual
和StarterMonthly
),我设置了这样的处理程序:
var handler = StripeCheckout.configure({
key: 'pk_test_qs8Ot1USopAZAyLN3gNXma0T',
image: '/img/stripe-logo.png',
locale: 'auto',
email: $scope.user.email,
token: function(token) {
console.log(token)
var tempObj = {
stripeToken : token,
email : $scope.user.email,
cost : $scope.plan.price * 100
plan : $scope.plan.name
}
$http.post('/api/makePayment', tempObj).then(function(data){
console.log('stripe data', data);
},function(err){
console.log('stripe error', err);
})
}
});
handler.open({
name: '<bizname>',
description: $scope.plan.name,
amount: $scope.plan.price * 100
});
Run Code Online (Sandbox Code Playgroud)
在我的Node路线中,我这样做:
exports.makePayment = function(req,res){
var stripeToken = req.body.stripeToken,
email = req.body.email,
cost = req.body.cost,
plan = …
Run Code Online (Sandbox Code Playgroud) 我有一个无序的列表,使用bootstraps"tabs"插件.代码如下所示:
<ul>
<li class="active span3"><a href="#ourAgency" data-toggle="tab"><i class="icon-building icon-3x"></i>Our Agency</a></li>
<li class="span3"><a href="#studentVisas" data-toggle="tab"><i class="icon-laptop icon-3x"></i>Student Visas</a></li>
<li class="span3"><a href="#workVisas" data-toggle="tab"><i class="icon-suitcase icon-3x"></i>Work Visas</a></li>
<li class="span3"><a href="#accreditation" data-toggle="tab"><i class="icon-legal icon-3x"></i>Accreditation</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我想使用CSS3来改变<a>
其父<li>
级没有类的所有链接的颜色.active
.
我尝试过这样的事情:
a:not(li.active>a){
color:grey;
}
Run Code Online (Sandbox Code Playgroud)
但无济于事.有没有办法做到这一点,还是我咆哮错误的树?
我知道$in
运算符,它似乎在数组中搜索项目的存在,但我只想找到匹配项,如果项目在数组中的第一个位置.
例如:
{
"_id" : ObjectId("0"),
"imgs" : [
"http://foo.jpg",
"http://bar.jpg",
"http://moo.jpg",
]
},
{
"_id" : ObjectId("1"),
"imgs" : [
"http://bar.jpg",
"http://foo.jpg",
"http://moo.jpg",
]
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找类似于的查询:
db.products.find({"imgs[0]": "http://foo.jpg"})
Run Code Online (Sandbox Code Playgroud)
这将/应该返回ObjectId("0")
但不是ObjectId("1")
,因为它只是检查数组中的第一个图像.
怎么能实现这一目标?我知道我可以创建一个单独的字段,其中包含一个字符串,firstImg
但这并不是我在此之后的真实情况.
我有一个简单的<input>
搜索过滤器设置为项目名称列表AngularJS
.
我的列表看起来像这样:
var uniqueLists = {
category1: ['item1', 'item2', 'item3' ... 'item180' ], // Real list contains ~180 items
category2: ['itemA', 'itemB', 'itemC' ... 'itemZZZ' ], // Real list contains ~1080 items
category3: ['otheritem1', 'otheritem2', 'otheritem3' ] // Real list contains 6 items
}
Run Code Online (Sandbox Code Playgroud)
我在Angular中遍历此列表并在<ul>
每个类别中打印出结果.
<div ng-repeat="(key,val) in uniqueLists">
<form ng-model="uniqueLists[index][0]">
<input ng-model="searchFilter" type="text" />
<ul>
<li ng-repeat="value in val | filter: searchFilter">
<label>
<input type="checkbox" ng-model="selectedData[key][value]" />
{{value}}
</label>
</li>
</ul>
</form>
</div> …
Run Code Online (Sandbox Code Playgroud) 我在Angular中有一个服务,它使用我的API获取用户信息并将其提供给我的控制器.它的设置如下:
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'ngResource', 'infinite-scroll', 'ui.bootstrap', 'ngCookies', 'seo'])
.service('userInfo', function($http, $cookies){
$http.get('/api/users/' + $cookies.id).
success(function(data) {
var userInfo = data.user[0];
return userInfo;
});
}). // other stuff comes after this
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我包括它:
function userProfile($scope, $cookies, userInfo, $http, $resource, $routeParams, $rootScope){
$scope.user = userInfo;
console.log('user info is')
console.log(userInfo);
Run Code Online (Sandbox Code Playgroud)
这没有返回数据,而如果我在控制器本身放置相同的服务功能,它返回就好了.我在这里错过了什么?从来没有在Angular中使用DI/Services,因此在某处可能是一个简单的错误.
我需要确保服务在控制器加载之前返回数据.如何实现这一目标