完成作业
This commit is contained in:
18
3.24作业.py
Normal file
18
3.24作业.py
Normal file
@@ -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}")
|
||||||
Reference in New Issue
Block a user