zoukankan      html  css  js  c++  java
  • 爬取凤凰客户端的FUN段子

    比较喜欢凤凰新闻客户端的FUN系列文章,所以就写了Python程序来下载所有这么段子的地址。

    下面程序只是下载第一页的所有文章的url,程序修改一下,就可以爬取所有的文章。

    #!/usr/bin/python
    #-*-coding:utf-8 -*-
    
    import requests
    import json
    import re
    headers={"Host":'i.ifeng.com',
            "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0",
            "Accept":"*/*",
            "Accept-Language":"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
            "Content-Type":"application/x-www-form-urlencoded",
            "X-Requested-With":"XMLHttpRequest",
            "Referer":"http://i.ifeng.com/news/djch/fun/dir?vt=5&cid=17899&mid=64DflZ"}
    
    rsp=requests.get("http://i.ifeng.com/news/djch/fun/ajaxlist.php?p=1&cid=17899&htmltype=dir",timeout=5,headers=headers)
    html=rsp.json()
    pattern=re.compile(r'aid=(.+?)&')
    aid_list=re.findall(pattern,str(html))
    for aid in aid_list:
            url="http://i.ifeng.com/news/djch/fun/news?vt=5&cid=0&aid=%s&mid=64DflZ&all=1&p=2"%aid
            print url
  • 相关阅读:
    ndoejs解析req,伪造http请求
    ndoejs创建多重文件夹
    路径path的正则通配符-nodejs
    例题1.5 快速排序
    例题1.3 整数划分问题
    sdcf day4 qaq模拟赛总结
    P1168 中位数
    浅谈LCA
    sdcf day1 qwq比赛题解
    2019山东夏令营划水记
  • 原文地址:https://www.cnblogs.com/tmyyss/p/4200058.html
Copyright © 2011-2022 走看看