Python网络爬虫03——简单爬虫实例

代码如下:

author = 'damao'

"""爬虫练习一:爬去迅播影院电影名称"""

from requests_html import HTMLSession


class TestSpiderFilmNames(object):

    def __init__(self):
        self._session = HTMLSession()
        self._url = 'http://www.0597ren.com/'
        self.get_link = self._session.get(self._url)

    @property
    def session(self):
        return self._session

    def get_all_links(self):
        get_link = self.get_link
        for _ in get_link.html.links:
            print(_)

    # 获取首页电影名称
    def __str__(self):  # get_film_names
        respones = self.get_link
        print(respones)
        content = respones.html.find('div.content',first=True)
        list_name = content.find('li')
        # print(content)
        list_film_data = []
        for li in list_name:
            moive_name = li .find('a',first=True).attrs['title']
            print(moive_name)
            list_film_data.append(moive_name)
        print("共获得{a}部电影。".format(a=len(list_film_data)))


if __name__ == '__main__':
    TestSpiderFilmNames().__str__()
    # t.get_all_links()
    # t.get_all_name()
    # t.get_film_names()






你可能感兴趣的