Python爬知乎热榜出现了Process finished with exit code 0怎么解决
问题描述:
Python爬知乎热榜出现了Process finished with exit code 0
我找过了试过了
1.更改python的解释器
2.重新部署过文件
但是依旧是Process finished with exit code 0
想知道是不是我的代码错了
import requests
from bs4 import BeautifulSoup
import re
headers={
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.40 Safari/537.36'
}
url='https://www.zhihu.com/hot'
html=requests.get(url,headers=headers)
soup=BeautifulSoup(html.text,'lxml')
divs=soup.select('.Topstory-content ')
for div in divs:
title = div.select('.HotList-list a .HotItem-title')[0].text
print('标题:',title)
soup=BeautifulSoup(html.text,'lxml')
run=soup.select('.Topstory-content .HotList-list p')
for r in run:
print(r.text)
答
返回零说明没有错误,通过我的检查发现你的选择返回的是空列表,说明你在匹配内容的时候没有匹配到,重新检查一下就行
答
-
Process finished with exit code 0
表示程序执行完毕,正常退出
换句话说,只有代码没报错,都会现实中这个。
- 在未登录的情况下,访问
https://www.zhihu.com/hot
返回登陆页面
你的元素定位是空,所以没有其他的内容可以输出