V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
thebabypiggy
V2EX  ›  Python

AttributeError: 'tuple' object has no attribute 'content'是什么意思?原部分代码如下

  •  
  •   thebabypiggy · 2018-03-26 21:33:01 +08:00 · 2641 次点击
    这是一个创建于 2424 天前的主题,其中的信息可能已经有所发展或是发生改变。
    def movies_from_url(urls):
    all_movie = []
    for u in urls:
    # r is a return datum,r is the object of response
    r = requests.get( u ),
    # page is bytes tape
    page = r.content
    # root is a structure(texture) of tree
    root = html.fromstring( page )
    # return a list
    moveie_divs = root.xpath( '//div[@class="item"]' )
    movies = [movie_from_div( div ) for div in moveie_divs]
    all_movie.extend( movies )
    return all_movie
    jameslan
        1
    jameslan  
       2018-03-27 01:16:39 +08:00 via Android   ❤️ 1
    结尾的逗号
    holajamc
        2
    holajamc  
       2018-03-27 09:39:55 +08:00   ❤️ 1
    r = requests.get( u ),
    r = requests.get( u )
    thebabypiggy
        3
    thebabypiggy  
    OP
       2018-03-27 14:43:17 +08:00
    @holajamc 我爬豆瓣 250 电影,相关图片内容都下载完了,然后报出这样的错误:Traceback (most recent call last):
    File "/Users/zzz/Documents/Untitled.py", line 96, in <module>
    main()
    File "/Users/zzz/Documents/Untitled.py", line 92, in main
    download_covers( movies )
    File "/Users/zzz/Documents/Untitled.py", line 81, in download_covers
    r = requests.get( imge_url )
    NameError: name 'imge_url' is not defined,相关代码是:
    def download_covers(movies):
    for m in movies:
    imag_url = m.cover_url
    r = requests.get( imge_url )
    path = 'covers/' + m.name.split( '/' )[0] + '.jpg'
    with open( path, 'wb' ) as f:
    f.write( r.content )


    def main():
    urls = urls_from_douban()
    movies = movies_from_url( urls )

    movie_log( movies )
    download_covers( movies )


    if __name__ == '__main__':
    main()

    感谢!
    thebabypiggy
        4
    thebabypiggy  
    OP
       2018-03-27 14:48:20 +08:00
    @holajamc 不用了,我 imge 打错了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5199 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 05:43 · PVG 13:43 · LAX 21:43 · JFK 00:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.