原因:代码段换行符失效,所有代码一行显示

解决方法:使用Chrome浏览器即可解决(使用Microsoft Edge会出现此问题)


效果展示:

# _*_ coding:utf-8 _*_
import requests
from lxml import etree
import pymongo client = pymongo.MongoClient('localhost',27017)
mydb = client['mydb']
timeline = mydb['timeline'] def get_time_info(url, page):
user_id = url.split('/')
user_id =user_id[4]
if url.find('page='):
page = page + 1
html = requests.get(url)
selector = etree.HTML(html.text)
infos = selector.xpath('//ul[@class="note-list"]/li') for info in infos:
dd = info.xpath('div/div/div/span/@data-datetime')[0]
type = info.xpath('div/div/div/span/@data-type')[0]
timeline.insert_one({'date':dd, 'type':type}) id_infos = selector.xpath('//ul[@class="note-list"]/li/@id')
if len(id_infos) >1:
feed_id = id_infos[-1]
max_id = feed_id.split('-')[1]
next_url = 'https://www.jianshu.com/users/%s/timeline?max_id=%s&page=%s' %(user_id, max_id, page) get_time_info(next_url, page) if __name__ =='__main__':
get_time_info('https://www.jianshu.com/users/9104ebf5e177/timeline', 1)

最新文章

  1. cocos2d-x屏幕分辨率,窗口大小总结
  2. PHP热身
  3. Linux 中 17 个 tar 命令实用示例
  4. html5.js让IE(包括IE6)支持HTML5元素方法
  5. [转载]QString 乱谈(3)-Qt5与中文
  6. Java基础(47):插入排序的Java封装(含原理,可运行,哨兵位的理解见VisualGo上面的动态分析)
  7. Android手机_软件安装目录
  8. leetcode 142. Linked List Cycle II ----- java
  9. wcf 获取客户端 IP
  10. 291. Word Pattern II
  11. Table of Contents - Nginx
  12. 陷阱~SQL全表扫描与聚集索引扫描
  13. 在mysql 中两种锁定问题
  14. Java日志工具之SLF4J
  15. Visual Studio For MacOS .NetCore开发踩坑记
  16. Mysql免安装版配置教程和常用命令图
  17. Game Engine Architecture 5
  18. Java学习笔记(二十四):单例设计模式singleton
  19. 【其他】【PL/SQL Developer】【1】解决PL/SQL Developer过期的情况
  20. 优秀前端工程师必备:" checkbox & radio--单钩 & 多钩 "大比较:你是♂||♀ , 还是 ♂&♀

热门文章

  1. 介绍HTML5几种存储方式
  2. (C#- 多线程) 在线程中创建object,共享问题。
  3. AttributeError: module 'datetime' has no attribute 'now'
  4. 损坏的RAID5
  5. SQL语法——Join详解
  6. sqli-labs(25a)
  7. 01 MySQL入门了解
  8. 第四周实验总结&实验报告
  9. SQL Server新老版本CE区别
  10. python检测编码