|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
from pyquery import PyQuery as pq
try:
url = 'https://www.zhihu.com/explore'
headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36(KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}
html = requests.get(url,headers=headers).text
doc = pq(html)
items = doc('.explore-tab .feed-item').items()
for item in items:
question = item.find('h2').text()
auther = item.find('.auther-link-line').text()
answer = pq(item.find('.content').html()).text()
print(question)
print(auther)
print(answer)
with open('explore.txt','a',encoding='utf-8') as f:
f.write('\n'.join([question,auther,answer]))
f.write('\n' + '=' *50 + '\n')
except:
print('异常')
如题,这是跟着一些书写的
|
|