V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
lzj307077687
V2EX  ›  Python

初学 Python 自己写了个程序爬自己博客

  •  
  •   lzj307077687 · 2019-08-21 17:39:44 +08:00 · 1958 次点击
    这是一个创建于 1681 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://github.com/straightedge4life/roblograbber
    有什么不足麻烦大佬们指正

    7 条回复    2019-08-22 17:57:22 +08:00
    CallMeReznov
        1
    CallMeReznov  
       2019-08-21 21:56:15 +08:00
    看到楼主头像,我下意识就想脱裤子.
    Iamnotfish
        2
    Iamnotfish  
       2019-08-21 22:50:06 +08:00
    干嘛存 SQL,存 CSV,TXT 不是更方便吗(认真脸
    wzwwzw
        3
    wzwwzw  
       2019-08-22 00:32:44 +08:00   ❤️ 1
    with ThreadPoolExecutor(max_workers) as pool:
    for item in args :
    future = pool.submit(fn , **item)
    futures.append(future)
    pool.shutdown()

    用了 with 会自动帮你上下文管理的 pool 的,不需要写 shutdown()
    lzj307077687
        4
    lzj307077687  
    OP
       2019-08-22 09:15:12 +08:00
    @Iamnotfish #2 一开始是写入 TXT 的 确实简单很多
    现在存 MYSQL 主要是之前安装 mysqlclient 填了个坑
    感觉不稍微试用下的话有点辜负之前的折腾 嘿嘿
    lzj307077687
        5
    lzj307077687  
    OP
       2019-08-22 09:15:54 +08:00
    @wzwwzw #3 又学到了~ 谢谢指正
    locoz
        6
    locoz  
       2019-08-22 17:23:46 +08:00   ❤️ 1
    看起来你之前应该不是写 Python 的?有些地方 PEP8 规范可以注意一下。
    然后为了提高效率可以试试 ayncio,用 aiohttp 这类异步的库。
    还有就是像 type(headers) is dict 这种可以写成 isinstance(headers, dict)。
    lzj307077687
        7
    lzj307077687  
    OP
       2019-08-22 17:57:22 +08:00
    @locoz #6 谢回复指导,下班回去了解一下~
    现在主要是写 PHP。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   958 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 21:38 · PVG 05:38 · LAX 14:38 · JFK 17:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.