diff --git a/3.24作业.py b/3.24作业.py new file mode 100644 index 0000000..2e009d3 --- /dev/null +++ b/3.24作业.py @@ -0,0 +1,18 @@ +import requests +from bs4 import BeautifulSoup +url='https://movie.douban.com/top250' +params={'start':0,'limit':25} +headers={ + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebkit/537.36(KHTML,like Gecko) Chrome/91.0.4472.124 Safari/537.36' +} +response=requests.get(url,params=params,headers=headers) +html_content="" +if response.status_code==200: + html_content=response.text + soup=BeautifulSoup(html_content,'lxml') + movie_items=soup.select('div.item') + for item in movie_items: + movie_name=item.find('span',class_='title').text + print(movie_name) +else: + print(f"请求失败,状态码:{response.status_code}") \ No newline at end of file