Python网络爬虫03——简单爬虫实例
代码如下:
author = 'damao'"""爬虫练习一:爬去迅播影院电影名称"""from requests_html import HTMLSessionclass 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._sessiondef 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 = https://www.it610.com/article/[]
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()
推荐阅读
- parallels|parallels desktop 解决网络初始化失败问题
- 猎杀IP
- python学习之|python学习之 实现QQ自动发送消息
- 逻辑回归的理解与python示例
- python自定义封装带颜色的logging模块
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum
- Python基础|Python基础 - 练习1
- 自媒体形势分析
- 数学大作战
- Python爬虫|Python爬虫 --- 1.4 正则表达式(re库)