用 python scrapy 和 BeautifulSoup 抓取网页?

时间:2021-07-30 14:28:02

标签: python beautifulsoup scrapy

我需要从一个页面中获取所有文章的链接,我尝试使用 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)

这两个函数都不打印任何数据,并且我确定元素和 css 类 enter image description here

0 个答案:

没有答案