python爬取imdb top250
python爬取imdb top250
1、前期准备
pycharm,请求库使用urllib.requests,解析库使用beautifulsoup
2、代码展示
from urllib import request
from bs4 import BeautifulSoup
response=request.urlopen('https://www.imdb.com/chart/top')
html = response.read()
html = html.decode("utf-8")
soup = BeautifulSoup(html,'lxml')
array = soup.select("td.titleColumn")
with open("C:/Users/15911/Desktop/1.txt","w",encoding='utf-8') as fo:
for item in array:
data=item.get_text().replace("\n", "")
fo.write(data)
fo.write('\n')
3、获取结果

浙公网安备 33010602011771号