小编asi*_*hal的帖子

Scrapy或Selenium或Mechanize来刮取网页数据?

我想从网站上抓一些数据.

基本上,该网站有一些表格显示,显示约50条记录.要获得更多记录,用户必须单击某个按钮进行ajax调用get并显示接下来的50条记录.

我以前有过Selenium webdriver(Python)的知识.我可以在Selenium中快速完成这项工作.但是,Selenium是一种更自动化的测试工具,它非常慢.

我做了一些研发,发现使用Scrapy或Mechanize,我也可以做同样的事情.

我应该为此选择Scrapy或Mechanize或Selenium吗?

mechanize scrapy web-scraping selenium-webdriver

11
推荐指数
1
解决办法
6897
查看次数

字符串迭代器不兼容

这是我的示例代码..

    const std::string strSchemeEnd("://");

    StringConstIteratorType itScheme = std::search(p_strUrl.begin(), p_strUrl.end(), strSchemeEnd.begin(), strSchemeEnd.end());
    StringConstIteratorType  l_itTempConst = p_strUrl.begin();
    m_strScheme.reserve(std::distance(l_itTempConst, itScheme));
    std::copy(l_itTempConst , itScheme, std::back_inserter(m_strScheme));
    boost::algorithm::to_lower(m_strScheme);
    l_itTempConst = strSchemeEnd.end();
    if ( itScheme == l_itTempConst )
        return;
Run Code Online (Sandbox Code Playgroud)

当我尝试运行该程序时,我发现以下错误

#if _ITERATOR_DEBUG_LEVEL == 2
    void _Compat(const _Myiter& _Right) const
        {   // test for compatible iterator pair
        if (this->_Getcont() == 0
            || this->_Getcont() != _Right._Getcont())
            {   // report error
            _DEBUG_ERROR("string iterators incompatible");
            _SCL_SECURE_INVALID_ARGUMENT;
            }
        }
Run Code Online (Sandbox Code Playgroud)

我经常遇到这个问题.有时一种解决方法有效,有时却没有.我想知道这个"字符串迭代器不兼容"错误的原因.有人能帮助我吗?

c++ stl

3
推荐指数
1
解决办法
3026
查看次数

将BSTR转换为LPCWSTR

这是我的需要

BSTR l_strArgs;
LPCWSTR  sth;
//----
//---
OutputDebugStringW(sth);
Run Code Online (Sandbox Code Playgroud)

如何将BSTR转换成LPCWSTR?

是否有任何头文件库将任何字符串类型(微软)转换为LPCWSTR类型?

c++ com atl

3
推荐指数
1
解决办法
7136
查看次数

Django模型中的外键

这是我的情况:SubCategory有外键Topic并且Topic有外键SubCategory.

class SubCategory(models.Model):
    name = models.CharField(max_length=100)
    slug = models.SlugField(max_length=110)
    description = models.TextField(default='')
    ordering = models.PositiveIntegerField(default=1)
    category = models.ForeignKey(Category)
    created_on = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(User)
    updated_on = models.DateTimeField(blank=True, null=True)
    updated_by = models.ForeignKey(User, related_name='+')
    num_topics = models.IntegerField(default=0)
    num_posts = models.IntegerField(default=0)
    last_topic = models.ForeignKey(Topic, related_name='+')


class Topic(models.Model):
    name = models.CharField(max_length=300)
    slug = models.SlugField(max_length=300)
    description = models.TextField(default='')
    subcategory = models.ForeignKey(SubCategory)
    created_on = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(User)
    updated_on = models.DateTimeField(blank=True, null=True)
    updated_by = models.ForeignKey(User, related_name='+')
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,它会给出以下错误:

NameError: …
Run Code Online (Sandbox Code Playgroud)

python django

3
推荐指数
2
解决办法
3289
查看次数

ajax在烧瓶视图中发布数据

这是我的视图功能

@app.route('/share', methods=['GET', 'POST'])
def share():
    form = ShareForm(request.form)
    if request.method == 'POST':
        title = form.title.data
        body = form.body.data
        share_id = form.share_id.data
        print 'form data %s %s %s' % (title, body, share_id)
        if not share_id:
            share = Shares(title, body, 'PUBLISHED', current_user.id)
            db.session.add(share)
            db.session.commit()
            form.share_id.data = share.id
        return jsonify({'status': 204, 'body': {'status': True}})
    else:
        return render_template('share.html', form=form)
Run Code Online (Sandbox Code Playgroud)

ajax post请求的代码

<script>
    $(function(){
      $('#share').on('click', function(e){
        e.preventDefault(); // preventing default click action
        $.ajax({
          url: '/share',
          type: 'post',
          contentType: "application/json; charset=utf-8",
          data: $('#share-form').serialize(),
          success: function(){ …
Run Code Online (Sandbox Code Playgroud)

python ajax flask python-2.7

3
推荐指数
1
解决办法
1465
查看次数

用于std :: thread的scoped线程包装器

我正在尝试制作一个范围的线程.

#include <iostream>
#include <thread>

class ScopedThread {
 public:
    template< class Function, class... Args>
    explicit ScopedThread( int id, Function&& f, Args&&... args)
        : m_thread( std::ref(f), std::forward<Args>(args)...)
        , id(std::move(id)) {
    }



    int getId() const { return id; }

    ~ScopedThread() { m_thread.join(); }
 private:
    std::thread m_thread;
    int id;

};

class Worker {
 public:
    Worker(int id): thd(id, &Worker::work, this) { }

    void work() {
       for( int i = 0; i < 10; i++)
        std::cout << "I am working" << std::endl;
    }


 private:
    ScopedThread …
Run Code Online (Sandbox Code Playgroud)

multithreading move-semantics c++11 clang++ stdthread

3
推荐指数
1
解决办法
282
查看次数

数字到qt的字符串转换

我发现一些奇怪的数字(浮点数)到字符串转换..

这是示例代码.

#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QString>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    qDebug()<<QString::number(50.5, 'f', 0);
    qDebug()<<QString::number(49.5, 'f', 0);

    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

这里的输出是

Starting /home/asit/qt/qstring1-build-desktop/qstring1...
"50" 
"50"
Run Code Online (Sandbox Code Playgroud)

输出应该是51和50.有人能说出这个输出背后的原因是什么?

qt

2
推荐指数
1
解决办法
6468
查看次数

模板错误中的模糊调用

谁能告诉我错误的原因?

错误是

C:\web\template1.cpp||In function 'int main()':|
C:\web\template1.cpp|23|error: call of overloaded 'swap(int&, int&)' is ambiguous|
C:\web\template1.cpp|6|note: candidates are: void swap(X&, X&) [with X = int]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note:                 void std::swap(_Tp&, _Tp&) [with _Tp = int]|
C:\web\template1.cpp|24|error: call of overloaded 'swap(double&, double&)' is ambiguous|
C:\web\template1.cpp|6|note: candidates are: void swap(X&, X&) [with X = double]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note:                 void std::swap(_Tp&, _Tp&) [with _Tp = double]|
C:\web\template1.cpp|25|error: call of overloaded 'swap(char&, char&)' is ambiguous|
C:\web\template1.cpp|6|note: candidates are: void swap(X&, X&) [with X = char]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note: …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
4490
查看次数

python3.3 setter中的无限递归

有人可以告诉我为什么在下面的代码中有一个递归?

class A:

    def __init__(self):
        self.a = 0

    @property
    def a(self):
        print ("called a getter")
        return self.a

    @a.setter
    def a(self, value):
        print ("called a setter")
        self.a = value


class B(A):

    def check(self):
        a = 10


if __name__ == "__main__":
    bb = B()
    bb.check()
Run Code Online (Sandbox Code Playgroud)

我必须从子类调用基类setter.我不被允许直接访问该成员.有人能告诉我怎么做其他方式吗?

python properties python-3.x

1
推荐指数
1
解决办法
397
查看次数

在c ++ 11条件变量中丢失信号

我对线程被唤醒和锁不可用有一点怀疑

std::mutex mut; 
std::queue<data_chunk> data_queue;   
std::condition_variable data_cond;

void data_preparation_thread() {    
    while(more_data_to_prepare())    {        
        data_chunk const data=prepare_data();        
        std::lock_guard<std::mutex> lk(mut);        
        data_queue.push(data);                      
        data_cond.notify_one(); //mutex is still locked here      
    }
}

void data_processing_thread() {
    while(true)    {
        std::unique_lock<std::mutex> lk(mut); 
        data_cond.wait(lk,[]{return !data_queue.empty();}); //what if lk could not acquire the mutex.
        data_chunk data=data_queue.front();        
        data_queue.pop();        
        lk.unlock();
        process(data);
        if(is_last_chunk(data))
            break;
    }
Run Code Online (Sandbox Code Playgroud)

}

在上面的示例中,data_preparation_thread()将数据放入队列中,并通知和线程等待condition_variable.

我的问题是,如果另一个线程醒来并发现相关的互斥锁仍然不可用,它会再次休眠.这不是错过信号的条件吗?

multithreading c++11

1
推荐指数
1
解决办法
462
查看次数