python爬取imdb top250

版权声明:文系原创,如需转载,请先申明 https://blog.csdn.net/mc0csdn02015/article/details/81608769

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

猜你喜欢

转载自blog.csdn.net/mc0csdn02015/article/details/81608769