1.拿到索引页的链接

import requests  #pip3 install requests  请求库  requests相较于urlibra 的封装程度更高。
import  re
'''
http://www.xiaohuar.com/list-3-0.html  第3页
http://www.xiaohuar.com/list-3-1.html  第2页
http://www.xiaohuar.com/list-3-2.html  第3页
http://www.xiaohuar.com/list-3-3.html  第4页
http://www.xiaohuar.com/list-3-4.html  第5页
'''



#1.发起请求,获取索引
def get_index_page(url):
    '''
    访问index配置, 注意:校花网的请求头user_agent可不加,至于其它的网站,一定要考虑。
    :return:
    '''
    response = requests.get(url)  #发完请求,得到一个响应的对象
    if response.status_code ==200:
        print(response.text)  #打印下:html的代码
        # return response.text

#2.解析索引页
def parse_index(index_page):
    '''
    解析库,把想要的内容解析出来。
    :param index_page:
    :return:
    '''
    re.findall("",index_page,re.S) #写一个规则,把网址都拿取到。



#3.爬取详情页的功能
def parse_detail_page():
    pass

def parse_detail():
    pass


def get_movie():
    pass

def main():
    base_url = 'http://www.xiaohuar.com/list-3-{page_num}.html'   #网址的规则
    for i in range(5):
        url = base_url.format(page_num=i)
        print(get_index_page(url)) #拿到链接内容


if __name__ == '__main__':
    main()
View Code

相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-09-30
  • 2021-11-06
猜你喜欢
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2021-11-07
  • 2021-04-29
相关资源
相似解决方案