我用python爬取一个网页时只显示了一条信息,这是代码部分,求大神指教

时间:2024-03-20 21:17:07

import requests
from bs4 import BeautifulSoup

url = 'https://ke.qq.com/course/list/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84c%E8%AF%AD%E8%A8%80?page=2'
res = requests.get(url)
#print(res.text)

html = res.text

soup = BeautifulSoup(html,'html.parser')
#print(soup)

infos = soup.find('ul',{'class':'course-card-list'}).find_all('li')
print(infos)

for info in infos:
    name = info.find('h4',{'class':'item-tt item-tt--oneline'})
    if name:
        name = name.find('a').get_text()
        print(name)

 

结果

我用python爬取一个网页时只显示了一条信息,这是代码部分,求大神指教