爬虫练习 用beautifulsoup 爬取猫眼top100
程序员文章站
2022-05-02 17:06:25
...
import requests
from bs4 import BeautifulSoup as bs
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1;Win64;x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
for i in range(10):
items=[]
resp=requests.get('https://maoyan.com/board/4?offset='+str(i*10),headers=headers)
html=resp.text
soup=bs(html,'lxml')
item=soup.find_all('dd')
items.extend(item)
for film in items:
dict={}
dict['index']=film.i.string
dict['name']=film.a.attrs['title']#film.find(name='p',attrs={'class':'name'}).string.strip()
dict['star']=film.find(name='p',attrs={'class':'star'}).string.strip()
dict['time']=film.find(name='p',attrs={'class':'releasetime'}).string.strip()
socre1=film.find(name='i',attrs={'class':'integer'}).string
score2=film.find(name='i',attrs={'class':'fraction'}).string
dict['score']=score1+score2
with open('film','a',encoding='utf-8')as f:
f.write(str(dict)+'\n')
下一篇: 关于java多线程死锁的问题
推荐阅读
-
Python爬虫实战用 BeautifulSoup 爬取电影网站信息
-
Python爬虫实战用 BeautifulSoup 爬取电影网站信息
-
Python爬虫实战之Requests+正则表达式爬取猫眼电影Top100
-
requests+BeautifulSoup爬取猫眼电影top100
-
Python爬虫实战之Requests+正则表达式爬取猫眼电影Top100
-
我要爬爬虫(6)-爬取猫眼Top100电影
-
Python爬虫练习五:爬取 2017年统计用区划代码和城乡划分代码(附代码与全部数据)
-
爬虫练习 用beautifulsoup 爬取猫眼top100
-
(爬虫基础)爬取猫眼Top100电影
-
python爬虫--猫眼电影TOP100榜爬取