我有两个数据库和两个模型:管理员和用户.
我想将我的模型同步到两个数据库; 管理模型到数据库A,用户模型到数据库B;
如果我将模型路径设置为INSTALLED_APPS
和syncdb
,则两个模型将同步到默认数据库.
如果我在syncdb
命令中设置数据库sync --database="B"
,那么两个模型将同步到数据库B.
所以我的问题是,如何将两个模型同步到两个数据库?
我有一些数字列表:
[1, 2, 3, 4, 5]
[2, 3, 4, 5, 6]
[3, 4, 5, 6, 7]
Run Code Online (Sandbox Code Playgroud)
我如何添加这些列表的元素,假设我使用的所有列表都是相同的长度?
以下是我希望从上述列表中获得的输出类型.
[6, 9, 12, 15, 18]
Run Code Online (Sandbox Code Playgroud)
我知道我需要一种循环 - 但我怎么能优雅地做到这一点?
当我编写parse()
函数时,我可以为一个页面同时生成请求和项目吗?
我想在页面A中提取一些数据,然后将数据存储在数据库中,并提取要遵循的链接(这可以通过CrawlSpider中的规则来完成).
我称A页面的链接页面是B页面,所以我可以编写另一个parse_item()来从B页面中提取数据,但是我想在B页面中提取一些链接,所以我只能使用规则来提取链接?如何解决Scrapy中的重复URL?
更新:我已经解决了问题,从日志中,我看到数据库经常打开和关闭.我把redis创建放在for循环中.所以...愚蠢的问题,如果有人像我一样记录,请检查循环.
我尝试关闭它并重新启动,但它仍然发生了.这是错误消息:
redis.exceptions.ConnectionError:连接localhost:6379的错误99.无法分配请求的地址.
我试图在redis中插入300000条记录(我的记忆足够大).但是在我插入大约30000条记录后,就会出现错误:
redis.exceptions.ConnectionError: Error 99 connecting localhost:6379. Cannot assign requested address.
Run Code Online (Sandbox Code Playgroud)
查看日志文件后,在成功插入30000条记录后,看起来redis已关闭.
以下是我的日志文件的一部分:
[32176] 11 Jun 20:59:27 - Accepted 127.0.0.1:36578
[32176] 11 Jun 20:59:27 - Client closed connection
[32176] 11 Jun 20:59:27 - Accepted 127.0.0.1:52327
[32176] 11 Jun 20:59:27 - Client closed connection
[32176] 11 Jun 20:59:27 - Accepted 127.0.0.1:52367
[32176] 11 Jun 20:59:27 - Client closed connection
[32176] 11 Jun 20:59:27 - Accepted 127.0.0.1:52368
[32176] 11 Jun 20:59:27 - Client closed connection
[32176] 11 Jun 20:59:27 - …
Run Code Online (Sandbox Code Playgroud) 按下选项卡完成后,我的vim会长时间扫描标签.我不知道它是关于插件还是vimrc文件.真的很烦人 我的vimrc是:https://gist.github.com/anonymous/5591546
它似乎当我按Tab键它甚至扫描/ usr/include目录,这需要很长时间,它让我发疯.
这样当我编辑一个文件时:
#include<stdio.h>
#include<ioste>
main()
{
int x = 8;
float y = 9.0;
char z = 'a';
int *p = &x;
float *q = &y;
char *r = &z;
printf("the *p address is %x\n",p);
printf("%d\n", sizeof(p));
printf("%d\n", sizeof(x));
printf("%d\n", sizeof(y));
printf("%d\n", sizeof(z));
printf("%d\n", sizeof(r));
printf("%d\n", sizeof(q));
printf("%c\n", *r);
printf("%f\n", *q);
}
Run Code Online (Sandbox Code Playgroud)
在包含它将开始告诉扫描标签,和vim卡住.
我有一个像以下html文件:
<form action="/2811457/follow?gsid=3_5bce9b871484d3af90c89f37" method="post">
<div>
<a href="/2811457/follow?page=2&gsid=3_5bce9b871484d3af90c89f37">next_page</a>
<input name="mp" type="hidden" value="3" />
<input type="text" name="page" size="2" style='-wap-input-format: "*N"' />
<input type="submit" value="jump" /> 1/3
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
如何在next_page中提取href""/ 2811457/follow?page = 2&gsid = 3_5bce9b871484d3af90c89f37"?
这是html的一部分,我打算说清楚.当我使用beautifulsoup时,
print soup.find('a',href=re.compile('follow?page'))
Run Code Online (Sandbox Code Playgroud)
它返回无,为什么?我是beautifulsoup的新手,我看过文档,但仍然感到困惑.
现在我用一种丑陋的方式:
urls = soup.findAll('a',href=True))
for url in urls:
if follow?page in url:
print url
Run Code Online (Sandbox Code Playgroud)
我需要一种更清晰优雅的方式.
scrapy shell是调试xpath表达式的好工具,但是在scrapspider中调试Rule的工具或方法是否有效?这意味着我怎么知道该规则按我的意愿工作。
我的规则是:
rules = (
Rule(SgmlLinkExtractor(allow=r'/search*',restrict_xpaths="//a[@id='pager_page_next']"), follow=False),
#Rule(SgmlLinkExtractor(allow=r'/chart/[\d]+s$'), callback='parse_toplist_page', follow=True),
)
Run Code Online (Sandbox Code Playgroud)
而且它没有遵循我想要的链接,那么如何调试?任何示例?
我不熟悉beautifulsoup的编码.
当我处理某些页面时,某些属性是中文,我想使用这个中文属性来提取标签.
例如,如下所示的html:
<P class=img_s>
<A href="/pic/93/b67793.jpg" target="_blank" title="????">
<IMG src="/pic/93/s67793.jpg">
</A>
</P>
Run Code Online (Sandbox Code Playgroud)
我想提取'/pic/93/b67793.jpg'所以我做的是:
img_urls = form_soup.findAll('a',title='????')
Run Code Online (Sandbox Code Playgroud)
遇到:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 0: ordinalnot in range(128)
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我做了两个方法,都失败了:一种方法是:
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
Run Code Online (Sandbox Code Playgroud)
另一种方式是:
response = unicode(response, 'gb2312','ignore').encode('utf-8','ignore')
Run Code Online (Sandbox Code Playgroud) 我开始使用tmux,它很棒,但是当我拆分窗口时,默认的hjkl是类似vim的窗格切换,为什么呢?如何输入hjkl?这是我的配置
unbind C-b
set -g prefix C-q
set -g default-terminal "screen-256color"
set -g display-time 3000
set -g history-limit 65535
set -g base-index 1
set -g pane-base-index 1
set -s escape-time 0
setw -g monitor-activity on
set -g visual-activity on
set-option -g mouse-select-pane on
#-- bindkeys --#
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
unbind '"'
bind-key - splitw -v
unbind %
bind-key | split-window -h
#-- statusbar …
Run Code Online (Sandbox Code Playgroud)