2016-05-25 19 views
13

Đây là câu hỏi đầu tiên của tôi về tràn ngăn xếp. Gần đây tôi muốn sử dụng linked-in-scraper, vì vậy tôi đã tải xuống và hướng dẫn "thu thập thông tin bịp nhặt linkedin.com" và nhận thông báo lỗi dưới đây. Đối với thông tin của bạn, tôi sử dụng anaconda 2.3.0 và python 2.7.11. Tất cả các gói có liên quan, bao gồm cả mẩu tin lưu niệm và sáu, được cập nhật bằng pip trước khi thực hiện chương trình.Phế liệu: AttributeError: đối tượng 'list' không có thuộc tính 'iteritems'

Traceback (most recent call last): 
    File "/Users/byeongsuyu/anaconda/bin/scrapy", line 11, in <module> 
    sys.exit(execute()) 
File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/cmdline.py", line 108, in execute 
settings = get_project_settings() 
File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/utils/project.py", line 60, in get_project_settings 
settings.setmodule(settings_module_path, priority='project') 
File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 285, in setmodule 
self.set(key, getattr(module, key), priority) 
    File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 260, in set 
self.attributes[name].set(value, priority) 
    File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 55, in set 
value = BaseSettings(value, priority=priority) 
    File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 91, in __init__ 
self.update(values, priority) 
    File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 317, in update 
for name, value in six.iteritems(values): 
    File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/six.py", line 599, in iteritems 
return d.iteritems(**kw) 

AttributeError: 'list' object has no attribute 'iteritems' 

Tôi hiểu rằng lỗi này bắt nguồn từ d không phải là loại từ điển nhưng loại danh sách. Và kể từ khi lỗi là từ các mã trên phế liệu, có thể nó là vấn đề về gói phế liệu hoặc sáu gói. Làm thế nào tôi có thể cố gắng sửa lỗi này?

EDIT: Đây là mã từ scrapy.cfg

# Automatically created by: scrapy start project 
    # 
    # For more information about the [deploy] section see: 
    # http://doc.scrapy.org/topics/scrapyd.html 
    [settings] 
    default = linkedIn.settings 

    [deploy] 
    #url = http://localhost:6800/ 
    project = linkedIn 
+0

Bạn có tệp cấu hình cho Scrapy không? Có vẻ như nó đang chờ đọc một từ điển nhưng thay vào đó lại tìm thấy một danh sách. –

+0

@ValentinLorentz Có Tôi đã thêm mã ở trên. Nhưng tôi nghĩ rằng nó không có thêm thông tin cho vấn đề này. Và lập trình viên xây dựng mã này nói rằng nó hoạt động tốt trên Ubuntu với python 2.7.6. – user124697

Trả lời

23

này được gây ra bởi sự hình liên kết trong scraper của settings:

ITEM_PIPELINES = ['linkedIn.pipelines.LinkedinPipeline'] 

Tuy nhiên, ITEM_PIPELINES được coi là một dict, according to the doc:

To activate an Item Pipeline component you must add its class to the ITEM_PIPELINES setting, like in the following example:

ITEM_PIPELINES = { 
    'myproject.pipelines.PricePipeline': 300, 
    'myproject.pipelines.JsonWriterPipeline': 800, 
} 

The integer values you assign to classes in this setting determine the order in which they run: items go through from lower valued to higher valued classes. It’s customary to define these numbers in the 0-1000 range.

Theo this question, nó từng là một danh sách, điều này giải thích tại sao scraper này sử dụng một danh sách. Vì vậy, bạn sẽ phải yêu cầu nhà phát triển của trình scraper cập nhật mã của họ hoặc tự đặt ITEM_PIPELINES.

0

Câu trả lời ngắn là ITEM_PIPELINES phải là từ điển không phải danh sách có khóa là lớp đường ống và giá trị một số nguyên xác định thứ tự chúng chạy: các mục đi qua từ các lớp có giá trị thấp hơn. Thông thường để xác định những con số này trong khoảng 0-1000. như được giải thích bởi @valentin Lorentz

Các vấn đề liên quan