elpais_spider.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:el_pais_editoriales 作者: rinze 项目源码 文件源码
def get_article_info(url):
    """
    Returns a dictionary with the article info.
    The dictionary contains the following fields:
    - date
    - title
    - tags (list of tags at the end of the article)
    - url
    """
    content = urllib2.urlopen(url)
    tree = html.parse(content)
    content.close()
    title = tree.xpath('//h1[@id="articulo-titulo"]/text()')[0]
    date = tree.xpath('//time//a/text()')[0].strip()
    tags = tree.xpath('//li[@itemprop="keywords"]/a/text()')
    url = url

    result = {'date': date, 'title': title, 'tags': tags, 'url': url}
    return(result)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号