提取时报相关的报道问题

问题遇到的现象和发生背景

返回空值

问题相关代码,请勿粘贴截图
!pip install bs4
from bs4 import BeautifulSoup
import requests

def get_news_of(keyword):
    content = requests.get('https://www.nytimes.com/')
    soup = BeautifulSoup(content.content, 'html.parser')
    #Add your code below.
    #use soup.find_all('a') like below
    all_a = soup.find_all('a')
    return_list = []
    #iterate over all the items in all_a and get by 'class' name
    #then check if keyword is present
    for tag_a in all_a:   
        a_title = tag_a.get_text('head',[]).strip()
        link = tag_a.get('href',[]).strip()
        for elem in a_title:
            if keyword in elem:
                return_list=a_title.append(link)
    return return_list

运行结果及报错内容

没有运行结果

我的解答思路和尝试过的方法

尝试append 及字典无结果

我想要达到的结果

返回有关的文章标题名及链接

看你打开的连接都是外网地址吧,我这里都打不开的,你应该改成国内https://cn.ibnews.com/nytimes这个地址吧

img

img