推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
brucebot
V2EX  ›  Python

如何用scrapy抓取数据时使用Xpath获得全部文本

  •  
  •   brucebot · Aug 30, 2013 · 7803 views
    This topic created in 4777 days ago, the information mentioned may be changed or developed.
    使用的是
    item['description'] = app.select('./li//text()').extract_unquoted()
    得到
    {"description": ["\n I visited the local ", "robotic", " club and recorded the preparation for the up-coming competition. I was invited to make a speech there\u00a0", "...", "\n "]

    请教应该怎么写,才能得到
    {"description": ["I visited the local robotic club and recorded the preparation for the up-coming competition. I was invited to make a speech there...“]
    这样的形式,就是只需要保留文本的部分?
    4 replies  •  1970-01-01 08:00:00 +08:00
    beordle
        1
    beordle  
       Aug 30, 2013   ❤️ 1
    "".join(app.select('./li//text()').extract_unquoted())
    brucebot
        2
    brucebot  
    OP
       Aug 30, 2013
    @beordle 这样出来的结果是
    {"description": "\n I visited the local robotic club and recorded the preparation for the up-coming competition. I was invited to make a speech there...\n“
    []不见了?
    beordle
        3
    beordle  
       Aug 30, 2013   ❤️ 1
    加上就好了嘛~
    item['description'] = ["".join(app.select('./li//text()').extract_unquoted())]
    如果需要/n换行的话
    item['description'] = "".join(app.select('./li//text()').extract_unquoted()).split('\n')
    可能还有一些细节问题。hack下即可
    brucebot
        4
    brucebot  
    OP
       Aug 30, 2013
    @beordle 非常感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1152 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 17:19 · PVG 01:19 · LAX 10:19 · JFK 13:19
    ♥ Do have faith in what you're doing.