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、获取结果

posted @ 2018-08-12 18:10  mangata  阅读(272)  评论(0编辑  收藏  举报