# -*- coding: utf-8 -*-
import urllib
import urllib.request
from bs4 import BeautifulSoup
url='https://www.zhihu.com/question/19763541'
request = urllib.request.Request(url)
response = urllib.request.urlopen(url)
page = response.read().decode('utf-8')
soup = BeautifulSoup(page,'html5lib')
# 问题是什么
question = soup.find_all('h2')[0]
print(question.find('span').string)
# 赞最多的回答
all_answer = soup.find_all('div',class_='zm-item-answer zm-item-expanded')
goodAnswer = 0
bestAnswer = 0
for answer in all_answer:
goodAnswer = answer.find('span',class_='count').string
#if(goodAnswer > bestAnswer):
# bestAnswer = goodAnswer
answerText = answer.find('div',class_='zm-editable-content clearfix')
print(goodAnswer +' '+ answerText.text[:10].replace('\n',''))
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦