小编oce*_*800的帖子

Scrapy - 了解CrawlSpider和LinkExtractor

所以我正在尝试使用CrawlSpider并理解Scrapy Docs中的以下示例:

import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor

class MySpider(CrawlSpider):
    name = 'example.com'
    allowed_domains = ['example.com']
    start_urls = ['http://www.example.com']

rules = (
    # Extract links matching 'category.php' (but not matching 'subsection.php')
    # and follow links from them (since no callback means follow=True by default).
    Rule(LinkExtractor(allow=('category\.php', ), deny=('subsection\.php', ))),

    # Extract links matching 'item.php' and parse them with the spider's method parse_item
    Rule(LinkExtractor(allow=('item\.php', )), callback='parse_item'),
)

def parse_item(self, response):
    self.logger.info('Hi, this is an item …
Run Code Online (Sandbox Code Playgroud)

python web-crawler scrapy scrapy-spider

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

连续添加所有1?

我有一个非常大的矩阵(大约4000000x2),它在整个矩阵中撒了1个.我想要做的是我只想在一行中添加所有1.

例如,如果我有这样的矩阵:

A = [0 0 4 1 0 0 1
     1 0 5 0 7 0 1 
     5 6 0 8 1 0 6 
     0 9 5 1 0 0 0]
Run Code Online (Sandbox Code Playgroud)

有没有办法总结所有的1行?例如,这里将是:

sum = [2
       2
       1
       1] 
Run Code Online (Sandbox Code Playgroud)

我知道如果你想加起整行,你可以使用sum(A,2).但是matlab中是否有一种方法可以将所有特定数字相加?我是matlab的新手,我非常感谢任何帮助,谢谢!

matlab row sum matrix

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

D3.js - 创建一个矩形?

我刚刚开始学习d3.js,我有一个非常简单的程序,它只是创建一个矩形:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title> D3 Slider </slider>
     <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<div>
    <script>
        //make the svg container 
        var svgContainer = d3.select("body").append("svg")
                                       .attr("width",200)
                                       .attr("height",200); 
        //make the rectangle 
        var rectangle = svgContainer.append("rect")
                                     .attr("x",150)
                                     .attr("y",50)
                                  .attr("width",50)
                               .attr("height",140);
    </script>
</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,矩形不会创建并且我得到一个空白屏幕?我是否必须将 SVG 元素添加到 div 中?对不起,如果这是一个简单的问题,但我就是想不通!

javascript svg d3.js

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

SQL - 循环遍历 MySQL 中的每一行表?

所以我有 2 个表,communication, 和movement。

communication有列fromID,timestamp有呼叫者的 ID 和呼叫的时间。然后,我有另一台movement已ID,timestamp,x,y,,有一个人,他们的位置的ID (x,y),而且它们在该位置的时间。

我想写一个看起来像这样的查询:

For every single row of communication(R)
    SELECT * FROM movement m
    WHERE m.ID = R.fromID && m.timestamp <= R.timestamp
    ORDER BY timestamp 
Run Code Online (Sandbox Code Playgroud)

基本上,这是在movement timestamp为给定的communication timestamp. 之后,最终,我想根据数据找到(x,y)呼叫的位置movement。

我该怎么做?我知道有一种基于集合的方法,但我不想那样做。我看了看cursors,但我觉得在这方面的表现很糟糕。

那么有没有办法用循环来做到这一点?我基本上想遍历 的每一行communication,然后得到结果。

我试过这样的事情:

DELMITER $$ 
CREATE PROCEDURE findClosestTimestamp() 
BEGIN 
DECLARE commRowCount DEFAULT …
Run Code Online (Sandbox Code Playgroud)

mysql sql loops stored-procedures cursors

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

Anaconda linux安装:conda:找不到命令

所以,我根据来自官方的指示安装巨蟒为Python 3.6 的下载页面,也这个.

我按照所有步骤,当有人问我是否要将Anaconda3安装位置添加到我的时候bashrc我说是的.当我打印出该文件的内容时,我有:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
   . /etc/bashrc
fi

# added by Anaconda 2.3.0 installer
export PATH="/home/username/anaconda/bin:$PATH"

# added by Anaconda3 4.3.1 installer
export PATH="/home/username/anaconda3/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

显然,它已被添加.但是,当我跑步时conda -V,我得到:

bash:conda:找不到commmand ...

还有什么可以导致这个?

python linux bash anaconda

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

C++ - 表达式必须是可修改的左值?

所以我现在正在实施一个BST,我正在尝试编写一个后继函数.这就是我现在所拥有的:

int BinarySearchTree::TREE_SUCCESSOR(node* x)
{

node* y = NULL;

if (x->right != NULL)
{
    return FIND_MIN(x->right);
}
else
{
    y = x->parent; 
    while (y != NULL && x = y->right)
    {
        x = y;
        y = y->parent;
    }
    return y->key; 
}
} 
Run Code Online (Sandbox Code Playgroud)

但是在这条线上:

while (y != NULL && x = y->right)
Run Code Online (Sandbox Code Playgroud)

我收到此错误y:

表达式必须是可修改的左值

为什么我收到此错误?

任何帮助将不胜感激,谢谢!

c++ lvalue binary-search-tree

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

Python - 使用min()在JSON对象中查找min值?

所以我有一个geojson对象,它具有:

"features" : [{"properties": {"rank": 10}},{"properties": {"rank": 2}}]
Run Code Online (Sandbox Code Playgroud)

等等.我想找到最低等级并使用min方法.所以我尝试过这样的事情:

features = geojson["features"]
min(features["properties"]["rank"])
Run Code Online (Sandbox Code Playgroud)

然后:

features = geojosn["features"]["properties"]["rank"]
min(features)
Run Code Online (Sandbox Code Playgroud)

并得到了这两个:

TypeError:List索引必须是切片的整数,而不是str

我究竟做错了什么?任何帮助将不胜感激,谢谢!

python json min geojson

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

Alfresco - 如何获取所有已签出的文档?

我正在尝试获取所有已签出文档的列表。不幸的是,我是 Alfresco 的新手,不太清楚如何做到这一点。我找到了这个:

https://wiki.alfresco.com/wiki/CMIS_Web_Scripts_Reference#Get_Checked_Out_Documents_.28getCheckedOutDocs.29

这是:

获取用户有权访问的已签出文档的列表。

但我不想要只有一个用户的签出文档,我想要所有用户的签出文档。有办法得到吗?

任何帮助将不胜感激,谢谢!

alfresco

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

C++如何向后打印字符串?

我试图std::string用这样的迭代器向后打印:

std::string back = "hello";
for(std::string::iterator it=back.end(); it!=back.begin(); --it)
{
    std::cout << (*it);
}
Run Code Online (Sandbox Code Playgroud)

但输出只会打印出来:

olle
Run Code Online (Sandbox Code Playgroud)

为什么不打印h?我尝试了几种不同的东西并玩弄它,但我似乎无法弄清楚原因.任何帮助将不胜感激,谢谢!:)

c++ string

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

Scrapy 根据条件停止分页?

所以我想从有分页的网站上抓取文章。基本上,每个页面都是文章链接的列表,蜘蛛程序以某种方法跟踪页面上的链接parse_article,以及连续的下一页链接。但是,有没有办法在抓取了一定数量的文章后停止这种情况呢?例如,这是我迄今为止使用的crawlspider:

rules = (

    #next page rule: 
    Rule(LinkExtractor(restrict_xpaths="//a[@class='next']"),follow=True)

    #Extract all internal links which follows this regex:
    Rule(LinkExtractor(allow=('REGEXHERE',),deny=()),callback='parse_article'),
)

def parse_article(self, response):
    #do parsing stuff here 
Run Code Online (Sandbox Code Playgroud)

当我解析完 150 篇文章后,我想停止关注下一页。即使我爬到了 150 多一点也没关系,我只是想在达到这个数字后就停止翻到下一页。有什么办法可以做到这一点吗?类似在parse_article方法中有一个计数器之类的东西吗?只是新手,scrapy所以我不确定要尝试什么....我研究了depth_limit,但我不太确定这就是我正在寻找的。

任何帮助将不胜感激,谢谢!

python pagination scrapy

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

Python:列表索引必须是整数,而不是str?

所以我的代码看起来像这样:

with open(completeCSV, 'r') as csvfile:
    test = csv.reader(csvfile, delimiter=';')
    for line in test:
        print(line)
        i = i + 1  # on the first line, i will equal 1
        count = line[0]
        if count == '1':
            for prof in proflist:  # vertex1=prof
                if line[1].lower() == proflist[prof]:
                    # if vertex1 is a professor, you want to keep the edge.
                    lines_to_keep.append(i)
                    break  # breaks and doesn't check the rest of profs
Run Code Online (Sandbox Code Playgroud)

它基本上读取CSV,并检查来自csv的值是否等于列表中的另一个值proflist.

我收到这个错误:

回溯(最近一次调用最后一次):文件"C:/Users/sskadamb/PycharmProjects/BetterDelimiter/filter.py",第50行,如果行[1] .lower()== proflist [prof]:TypeError:list indices必须是整数,而不是str

是因为proflist[prof] …

python csv list

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