上传文件至 /
This commit is contained in:
33
6.23
Normal file
33
6.23
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup as bs
|
||||||
|
import json
|
||||||
|
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'}
|
||||||
|
url="https://movie.douban.com/top250?start=0"
|
||||||
|
data=[]
|
||||||
|
resp = requests.get(url, headers = headers)
|
||||||
|
resp.encoding='uft-8'
|
||||||
|
soup= bs(resp.text,"html.parser")
|
||||||
|
items= soup.find_all("div",class_="item")
|
||||||
|
#print(items[0])
|
||||||
|
for i in range(len(items)):
|
||||||
|
print(i)
|
||||||
|
title=items[i].find("span",class_="title").get_text()
|
||||||
|
|
||||||
|
actors=items[i].find("div",class_="bd").get_text().strip()
|
||||||
|
try:
|
||||||
|
actors=actors.split("主演:")[1].split("\n")[0]
|
||||||
|
except:
|
||||||
|
actors="无"
|
||||||
|
try:
|
||||||
|
quote=items[i].find("div",class_="bd").find("p",class_="quote").get_text().strip()
|
||||||
|
except:
|
||||||
|
quote="无"
|
||||||
|
data.append({
|
||||||
|
"title":title,
|
||||||
|
"actor":actors,
|
||||||
|
"quote":quote
|
||||||
|
})
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
with open("movie.json","w",encoding="utf-8") as f:
|
||||||
|
json.dump(data,f,ensure_ascii=False,indent=4)
|
||||||
Reference in New Issue
Block a user