Python 查找特定网站的CSS选择器

Python 查找特定网站的CSS选择器,python,web-scraping,Python,Web Scraping,我一直试图从这个网站上获取产品名称和价格,但不幸的是,我无法获得正确的CSS选择器。我还使用了CSS选择器小工具。我也知道html和css,我自己也读过。我认为css选择器是正确的,但由于某些原因,我无法提取数据 def parse(self, response): items = DenItem() all_div = response.css('div.collection-product') for di

我一直试图从这个网站上获取产品名称和价格,但不幸的是,我无法获得正确的CSS选择器。我还使用了CSS选择器小工具。我也知道html和css,我自己也读过。我认为css选择器是正确的,但由于某些原因,我无法提取数据

   def parse(self, response):
      

        items = DenItem()
        all_div = response.css('div.collection-product')
       
        for div in all_div:
            product_name = div.css(".collection-product-name font font::text").extract()
            _new_price = div.css('div.collection-product-price > a > font > font::text').extract()  # .replace("Rs", "")
            _new_price = [s.replace("$", "") for s in _new_price]
            _new_price = [s.replace(",", "") for s in _new_price]
            _old_price = div.css("main#setembro section:nth-child(5) > div > div > div > div > ul > div.owl-wrapper-outer > div > div:nth-child(3) > li > div > div.collection-product-price-content > p.collection-product-price > del > font > font::text").extract()  # .replace("Rs", "")
            _old_price = [n.replace("R $", "") for n in _old_price]
            _old_price = [n.replace(",", "") for n in _old_price]
            items['product_name'] = product_name
            items['_new_price'] = _new_price
            items['_old_price'] = _old_price
            if len(items['_new_price']) == 0:
                items['_new_price'] = '0'
            if len(items['_old_price']) == 0:
                items['_old_price'] = '0'

            yield items

我发现从另一个url动态返回的内容。使用F5刷新页面时,可以在“网络”选项卡中找到此选项

import requests

r = requests.get('https://dentalspeed.com/vitrines/app-vitrine__home--estetica').json()
print(r)

根据您想要的产品的完整列表,您可能需要跟踪其他URL

共享到目前为止您拥有的代码,如果没有这些代码,您只是请求他人为您执行。我已经共享了哪些产品?有很多。另外,div.collection-product不会为我生成任何结果,因此您不会执行循环。我不明白?产品和价格是动态加载的。例如,Escolha of ertas Por specialidade,这些产品的信息是从我上面显示的url加载的。当您使用浏览器时,它会向其他URI发出附加请求,而不仅仅是您开始使用的url。使用请求不会捕获这些附加请求。但是,您可以使用“浏览器网络”选项卡找出这些其他请求,然后使用请求对这些URI进行xhr调用。