18 lines
659 B
Python
18 lines
659 B
Python
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}") |