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
DrPython
V2EX  ›  Python

求助:为什么这里要这样写?

  •  
  •   DrPython · 2019-03-07 22:46:27 +08:00 · 850 次点击
    这是一个创建于 1875 天前的主题,其中的信息可能已经有所发展或是发生改变。
    想获取知乎发现页的问题的答案内容,代码如下:
    import requests
    from pyquery import PyQuery as pq

    url = 'https://www.zhihu.com/explore'
    headers = {
    'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
    }
    html = requests.get(url, headers=headers)

    doc = pq(html.text)
    results = doc('.explore-tab .feed-item').items()
    for item in results:
    answer = pq(item.find('.content').html()).text() #这里为什么直接写 item.find('.content').text()出来的
    内容是夹带符号,而且内容是不完整的。这段代码要怎么理解?

    第一次提问,写的有点乱。
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1070 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:35 · PVG 06:35 · LAX 15:35 · JFK 18:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.