美文网首页
二、爬取伯乐在线

二、爬取伯乐在线

作者: Im渣渣 | 来源:发表于2017-10-26 16:21 被阅读0次
    1. 创建main函数,调试scrapy

    -- coding: utf-8 --

    author = 'wujiee'

    from scrapy.cmdline import execute

    import sys
    import os

    sys.path.append(os.path.dirname(os.path.abspath(file)))
    execute(["scrapy","crawl","jobbole"])

    cmd命令中,运行scrapy crawl jobbole
    如果出错,则安装如下包pip install pypiwin32

    2.xpath用法
    articleTitle = response.xpath('//[@id="post-112760"]/div[1]/h1/text()') --text()可以提取标签里的内容
    tagList = response.xpath('//
    [@id="post-112760"]/div[2]/p/a/text()').extract() --extract()提取两个a标签的内容,组成一个数据列表
    tags = ",".join(tagList) --join()函数拼接字符串,参数为list列表类型

    相关文章

      网友评论

          本文标题:二、爬取伯乐在线

          本文链接:https://www.haomeiwen.com/subject/ycykpxtx.html