我试图以非常基本的方式抓取网站.但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 …
当我尝试将TortoiseGit推送到Bitbucket作为初始源代码时,出现错误:
远程名称不能为空。
我已经使用了TortoiseGit很多时间,即使我从未输入任何远程名称,也从未遇到此错误的任何问题。仅当我尝试推动时才会发生。我可以保证。
如何解决呢?
将数据插入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脚本,我希望每天只运行一次.我对crontab命令进行了一些研究,似乎这样做了,但每天都在固定的时间.问题是我的计算机不会整天运行,并且运行它的具体时间是不可能的.我能做什么?
日志文件可以帮助吗?我想crontab每5分钟左右做一次扫描日志文件以查看当天的任何运行情况.
我mysql-python在我的机器上安装了v1.2.4(Windows 8).我使用的是Python 2.7.每次尝试升级到v1.2.5时,我总是得到以下错误.(从v1.3.7开始仍然发生)
Run Code Online (Sandbox Code Playgroud)C:\Users\User\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\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
Run Code Online (Sandbox Code Playgroud)---------------------------------------- Rolling back uninstall of mysql-python Command "c:\python27\python.exe -u -c "importsetuptools,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 \
我已经尝试过(并且没有工作):
我想编写一个交互式Bezier曲线生成器,唯一的输入是图形上的鼠标单击坐标(使用matplotlib.pyplot)
因此,我想知道如何获取这些坐标,以及如何使用class和self.functions尽可能简单地将它们堆叠在x轴和y轴的两个列表中。
谢谢 !
双拼
使用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) 我对我的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' …
当我尝试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)
有谁知道如何解决这个错误?
我的 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 ×9
python-2.7 ×3
scrapy ×3
bitbucket ×1
coordinates ×1
cron ×1
cron-task ×1
crontab ×1
database ×1
dictionary ×1
django ×1
encoding ×1
git ×1
git-push ×1
iterable ×1
keyerror ×1
match ×1
matplotlib ×1
mongoengine ×1
mouseevent ×1
mysql ×1
mysql-python ×1
regex ×1
sql ×1
sql-server ×1
tortoisegit ×1
windows ×1