1

While following a tutorial about web scraping in Node JS, I ran into this problem when running this script in the terminal:

Object #<Object> has no method 'attr'

Here's the script I'm using:

var request = require('request'),
    cheerio = require('cheerio'),
    urls = [];

request('http://www.reddit.com', function (err, resp, body) {
    if (!err && resp.statusCode == 200) {
        var $ = cheerio.load(body);
        $('a.title', '#siteTable').each(function() {
            var url = this.attr('href');
            urls.push(url)
        });

        console.log(urls);
    }
});

Any ideas on how to fix this script so it doesn't throw an error? Any help would be really appreciated!


Negative id value in SQLite Android

In the main activity I create database

class DBHelper extends SQLiteOpenHelper {

        public DBHelper(Context context) {

               super(context, "myDB", null, 1);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
          db.execSQL("create table mytable ("
                  + "id integer primary key autoincrement," 
                  + "name text," 
                  + "obId text," 
                  + "latit text,"
                  + "long text" + ");");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        }
      }

In the second activity I call the class of database

MainActivity myActivity = new MainActivity();
dbHelper = myActivity.new DBHelper(myActivity);

And insert data

ContentValues cv = new ContentValues();
db = openOrCreateDatabase("myDB.db", SQLiteDatabase.OPEN_READWRITE, null);
cv.put("name", textViewName.getText().toString());
long rowID = db.insert("mytable", null, cv);
db.insert("mytable", null, cv);
dbHelper.close();

The output "rowID" is "-1". I do not understand why this is happening

4

1 回答 1

3

默认情况下,范围对象this不是 jQuery 对象。

var url = this.getAttribute("href");
// or
var url = $(this).attr("href");
于 2014-04-22T19:05:57.340 回答