我想从网站上抓一些数据.
基本上,该网站有一些表格显示,显示约50条记录.要获得更多记录,用户必须单击某个按钮进行ajax调用get并显示接下来的50条记录.
我以前有过Selenium webdriver(Python)的知识.我可以在Selenium中快速完成这项工作.但是,Selenium是一种更自动化的测试工具,它非常慢.
我做了一些研发,发现使用Scrapy或Mechanize,我也可以做同样的事情.
我应该为此选择Scrapy或Mechanize或Selenium吗?
这是我的示例代码..
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)
我经常遇到这个问题.有时一种解决方法有效,有时却没有.我想知道这个"字符串迭代器不兼容"错误的原因.有人能帮助我吗?
这是我的需要
BSTR l_strArgs;
LPCWSTR sth;
//----
//---
OutputDebugStringW(sth);
Run Code Online (Sandbox Code Playgroud)
如何将BSTR转换成LPCWSTR?
是否有任何头文件库将任何字符串类型(微软)转换为LPCWSTR类型?
这是我的情况: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) 这是我的视图功能
@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) 我正在尝试制作一个范围的线程.
#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) 我发现一些奇怪的数字(浮点数)到字符串转换..
这是示例代码.
#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.有人能说出这个输出背后的原因是什么?
谁能告诉我错误的原因?
错误是
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) 有人可以告诉我为什么在下面的代码中有一个递归?
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.我不被允许直接访问该成员.有人能告诉我怎么做其他方式吗?
我对线程被唤醒和锁不可用有一点怀疑
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.
我的问题是,如果另一个线程醒来并发现相关的互斥锁仍然不可用,它会再次休眠.这不是错过信号的条件吗?
c++ ×3
python ×3
c++11 ×2
ajax ×1
atl ×1
clang++ ×1
com ×1
django ×1
flask ×1
mechanize ×1
properties ×1
python-2.7 ×1
python-3.x ×1
qt ×1
scrapy ×1
stdthread ×1
stl ×1
web-scraping ×1