推荐学习书目
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 · Mar 26, 2018 · 3211 views
    This topic created in 3058 days ago, the information mentioned may be changed or developed.
    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  
       Mar 27, 2018 via Android   ❤️ 1
    结尾的逗号
    holajamc
        2
    holajamc  
       Mar 27, 2018   ❤️ 1
    r = requests.get( u ),
    r = requests.get( u )
    thebabypiggy
        3
    thebabypiggy  
    OP
       Mar 27, 2018
    @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
       Mar 27, 2018
    @holajamc 不用了,我 imge 打错了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   830 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:58 · PVG 05:58 · LAX 14:58 · JFK 17:58
    ♥ Do have faith in what you're doing.