Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么运行以下程序只能获取豆瓣的第一个电影? #4

Open
guhailong18 opened this issue Nov 24, 2019 · 1 comment
Open

Comments

@guhailong18
Copy link

import requests
from bs4 import BeautifulSoup
def get_movie():
headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
'Host':'movie.douban.com'}
movie_list =[]
for i in range(0,10):
link = 'https://movie.douban.com/top250?start=' + str(i*25)

	r = requests.get(link,headers =headers,timeout=8)
	print(str(i+1),"内容:",r.status_code)
	soup = BeautifulSoup(r.text,"lxml")
	div_list = soup.find_all('div',class_='hd')
	for each in div_list:
		movie = each.a.span.text.strip()
		movie_list.append(movie)
		return movie_list

print(get_movie())

运行结果:1 内容: 200
['肖申克的救赎']

@aksan9527
Copy link

把源代码贴上来吧,这样也好解决一些。应该是忘记缩进或者循环出了问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants