小编Ami*_*ini的帖子

Scrapy没有抓取所有页面

我试图以非常基本的方式抓取网站.但Scrapy没有抓取所有链接.我会解释如下情况─

main_page.html - >包含指向a_page.html,b_page.html,c_page.html的
链接a_page.html - >包含指向a1_page.html的链接,a2_page.html
b_page.html - >包含指向b1_page.html,b2_page.html
c_page的链接.html - >包含指向c1_page.html的链接,c2_page.html
a1_page.html - >包含指向b_page.html的链接
a2_page.html - >包含指向c_page.html的链接
b1_page.html - >包含指向a_page.html的链接
b2_page.html - >包含指向c_page.html的链接
c1_page.html - >包含指向a_page.html的链接
c2_page.html - >包含指向main_page.html的链接

我在CrawlSpider中使用以下规则 -

Rule(SgmlLinkExtractor(allow = ()), callback = 'parse_item', follow = True))

但抓取结果如下 -

DEBUG:Crawled(200)http://localhost/main_page.html>(referer:None)2011-12-05 09:56:07 + 0530 [test_spider] DEBUG:Crawled(200)http:// localhost/a_page. html>(referer: http://localhost/main_page.html )2011-12-05 09:56:07 + 0530 [test_spider] DEBUG:Crawled(200)http://localhost/a1_page.html>(referer:http ://localhost/a_page.html )2011-12-05 09:56:07 + 0530 [test_spider] DEBUG:Crawled(200)http://localhost/b_page.html>(referer:http:// localhost/a1_page .html)2011-12-05 09:56:07 + 0530 [test_spider] DEBUG:Crawled(200)http://localhost/b1_page.html>(referer:http://localhost/b_page.html)2011-12 -05 09:56:07 …

python scrapy

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

TortoiseGit错误:“远程名称不能为空”

当我尝试将TortoiseGit推送到Bitbucket作为初始源代码时,出现错误:

远程名称不能为空。

我已经使用了TortoiseGit很多时间,即使我从未输入任何远程名称,也从未遇到此错误的任何问题。仅当我尝试推动时才会发生。我可以保证。

如何解决呢?

错误如何显示

windows git bitbucket git-push tortoisegit

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

错误'字符串或二进制数据将在Microsoft SQL中被截断'

将数据插入Microsoft SQL时出现此错误.

错误:('22001','[22001] [Microsoft] [SQL Server的ODBC驱动程序13] [SQL Server]字符串或二进制数据将被截断.(8152)(SQLParamData); [01000] [Microsoft] [ODBC驱动程序13 for SQL Server] [SQL Server]该语句已被终止.(3621)')

仅供参考,我使用Python 2.7和pyodbc库.

那个错误是什么?我该怎么做才能解决它?

python sql database sql-server python-2.7

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

非时间特定的一天crontab?

我有一个python脚本,我希望每天只运行一次.我对crontab命令进行了一些研究,似乎这样做了,但每天都在固定的时间.问题是我的计算机不会整天运行,并且运行它的具体时间是不可能的.我能做什么?

日志文件可以帮助吗?我想crontab每5分钟左右做一次扫描日志文件以查看当天的任何运行情况.

python cron crontab scheduled-tasks cron-task

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

无法在Windows中安装mysql-python(较新版本)

我mysql-python在我的机器上安装了v1.2.4(Windows 8).我使用的是Python 2.7.每次尝试升级到v1.2.5时,我总是得到以下错误.(从v1.3.7开始仍然发生)

C:\Users\User\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\
Run Code Online (Sandbox Code Playgroud)

9.0\VC\Bin\cl.exe/c/nologo/Ox/MD/W3/GS-/DNDEBUG -Dversion_info =(1,2,5,'fi nal',1)-D__version __ = 1.2.5"-IC :\ Program Files(x86)\ MySQL\MySQL Connector C 6. 0.2\include"-Ic:\ python27\include -Ic:\ python27\PC /Tc_mysql.c /Fobuild\temp.wi n32-2.7\Release_mysql.obj/zl _mysql.c _mysql.c(42):致命错误C1083:无法打开包含文件:'config-win.h':没有这样的文件或目录错误:命令'C:\ Users\User\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe'失败,退出状态为2

----------------------------------------   Rolling back uninstall of mysql-python Command "c:\python27\python.exe -u -c "import
Run Code Online (Sandbox Code Playgroud)

setuptools,tokenize; file ='c:\\ users\user\appdata\local\temp\pip-build-utz7of\MySQL-python\setup.py'; ex ec(compile(getattr(tokenize,'open',open)(file) .read().replace('\ r \n','\n'),file,'exec'))"install --record c:\ users\user\appdata\local\temp\pip-osy _cg- record\install-record.txt --single-version-external-managed --compile"fai led with error code 1 in c:\ users\user\appdata\local\temp\pip-build-utz7of\MySQL -python \

我已经尝试过(并且没有工作):

  1. 安装VS2010
  2. 改变Python路径 …

python mysql python-module mysql-python python-2.7

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

Python:鼠标单击的坐标尽可能简单

我想编写一个交互式Bezier曲线生成器,唯一的输入是图形上的鼠标单击坐标(使用matplotlib.pyplot)

因此,我想知道如何获取这些坐标,以及如何使用class和self.functions尽可能简单地将它们堆叠在x轴和y轴的两个列表中。

谢谢 !

双拼

python matplotlib mouseevent coordinates

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

为什么使用正则表达式finditer()而不是findall()

使用finditer()if 的优点findall()是什么? findall()返回所有匹配项,同时finditer()返回匹配对象,该对象不能直接作为静态列表处理.

例如:

import re
CARRIS_REGEX = (r'<th>(\d+)</th><th>([\s\w\.\-]+)</th>'
                r'<th>(\d+:\d+)</th><th>(\d+m)</th>')
pattern = re.compile(CARRIS_REGEX, re.UNICODE)
mailbody = open("test.txt").read()
for match in pattern.finditer(mailbody):
    print(match)
print()
for match in pattern.findall(mailbody):
    print(match)
Run Code Online (Sandbox Code Playgroud)

输出:

<_sre.SRE_Match object at 0x00A63758>
<_sre.SRE_Match object at 0x00A63F98>
<_sre.SRE_Match object at 0x00A63758>
<_sre.SRE_Match object at 0x00A63F98>
<_sre.SRE_Match object at 0x00A63758>
<_sre.SRE_Match object at 0x00A63F98>
<_sre.SRE_Match object at 0x00A63758>
<_sre.SRE_Match object at 0x00A63F98>

('790', 'PR. REAL', '21:06', '04m')
('758', 'PORTAS BENFICA', '21:10', '09m')
('790', 'PR. …
Run Code Online (Sandbox Code Playgroud)

python regex iterable match string-matching

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

Django:更改模型中的字段类型时出现 FieldDoesNotExist 错误

我对我的models.py. 我将字段从 更改FileField()为ImageWithThumbsField()

from mongoengine import *
from gradfounder.settings import DBNAME
from embed_video.fields import EmbedVideoField
from thumbs import ImageWithThumbsField

##########################################
# Mongoengine registration/authentication
#from mongoengine.django.auth import User
##########################################

#connect(DBNAME)
# connect(DBNAME, host='127.0.0.1', port=27017)
connect(DBNAME, host='xxx.xxx.xxx.xxx', port=27017)

class Author(Document):
    # photo = FileField()
    photo = ImageWithThumbsField(upload_to="avatars")
    photoname = StringField()
Run Code Online (Sandbox Code Playgroud)

然后我得到了这个错误

  File "C:\Python27\lib\site-packages\mongoengine\base\document.py", line 80, in
 __init__
    raise FieldDoesNotExist(msg)
FieldDoesNotExist: The field 'photo' does not exist on the document 'Author'
Run Code Online (Sandbox Code Playgroud)

我尝试迁移,syncdb但出现错误DatabaseError: (1050, "Table 'profiles_profile' …

python django django-models django-file-upload mongoengine

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

Scrapy - TypeError:无法转换unicode主体 - HtmlResponse没有编码

当我尝试HtmlResponse在Scrapy中构造一个像这样的对象:

scrapy.http.HtmlResponse(url=self.base_url + dealer_url[0], body=dealer_html)
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

Traceback (most recent call last):

  File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\internet\defer.py", line 588, in _runCallbacks

    current.result = callback(current.result, *args, **kw)

  File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>\<project_name>\<project_name>\spiders\fwi.py", line 69, in parse_items

    dealer_page = scrapy.http.HtmlResponse(url=self.base_url + dealer_url[0], body=dealer_html)

  File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\http\response\text.py", line 27, in __init__

    super(TextResponse, self).__init__(*args, **kwargs)

  File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\http\response\__init__.py", line 18, in __init__

    self._set_body(body)

  File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\http\response\text.py", line 43, in _set_body

    type(self).__name__)

TypeError: Cannot convert unicode body - HtmlResponse has no encoding
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这个错误?

python encoding scrapy python-2.7 scrapy-spider

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

无法从 Scrapy stats 字典中获取值

我的 scrapy 中有这个管道,我需要从 Scrapy 统计信息中获取信息

class MyPipeline(object):

    def __init__(self, stats):
        self.stats = stats

    @classmethod
    def from_crawler(cls, crawler):
        return cls(crawler.stats)

    def process_item(self, item, spider):           
        print self.stats.get_stats()['item_scraped_count']
        return item
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,我收到此错误

Traceback (most recent call last):
  File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\twisted\internet\defer.py", line 649, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
  File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>\<project_name>\<project_name>\pipelines.py", line 35, in process_item
    print self.stats.get_stats()['item_scraped_count']
KeyError: 'item_scraped_count'
Run Code Online (Sandbox Code Playgroud)

如果这不是获取统计值的正确方法,那么我该怎么办?

python dictionary scrapy keyerror scrapy-pipeline

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