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

2018-03-26 21:33:01 +08:00
 thebabypiggy
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
2569 次点击
所在节点    Python
4 条回复
jameslan
2018-03-27 01:16:39 +08:00
结尾的逗号
holajamc
2018-03-27 09:39:55 +08:00
r = requests.get( u ),
r = requests.get( u )
thebabypiggy
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
2018-03-27 14:48:20 +08:00
@holajamc 不用了,我 imge 打错了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/441614

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX