我需要从一个页面中获取所有文章的链接,我尝试使用 python scrapy 和 beautifulsoup 库来做到这一点,但实际上什么也没有出现
Scrapy 版本
import scrapy
class CnnSpider(scrapy.Spider):
name = "cnn"
start_url = ['https://edition.cnn.com/business/india/index.html']
def parse(self, response):
for links in response.css('span.cd__headline-text'):
print(links)
美汤版
def links():
url = "https://edition.cnn.com/business/india/index.html"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
l = soup.find_all('span',class_="cd__headline-text")
for element in l :
print(element)