|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我没有获取页数 直接写的1-10页 也只获取了名字和评分
import requests
import bs4
def open_url(url):
req = requests.get(url)
return req
def find_url(req):
soup = bs4.BeautifulSoup(req.text,'html.parser')
movie = []
target = soup.find_all('div',class_='hd')
for each in target:
movie.append(each.a.span.text)
point = []
targets = soup.find_all('span',class_='rating_num')
for one in targets:
point.append('评分:%s' %one.txt)
result = []
for i in range(len(movie)):
result.append(movie[i]+one[i])
return result
def main():
net = 'https://movie.douban.com/top250'
result = []
for i in range(1,11):
url = net + '?start='+ str(i*25) + '&filter='
req = open_url(url)
result.extend(find_url(req))
with open('豆瓣top250.txt','w',encoding='utf-8') as f:
for each in result:
f.write(each)
if __name__ == '__main__':
main()
|
|