python scrapy中的xpath和css选择器

import scrapy

class ShSpider(scrapy.Spider):
  name = 'sh'
  start_urls = [
    'https://weather.com/zh-CN/weather/today/l/7f14186934f484d567841e8646abc61b81cce4d88470d519beeb5e115c9b425a']

  def parse(self, response):
    # 每日预报
    for li in response.css('div.DailyWeatherCard--TableWrapper--12r1N ul li'):
      yield {
    
    
        "name": li.css('a>h3>span::text').get(),
        "text": li.xpath('a/h3/span/text()').get()
      }
    pass

猜你喜欢

转载自blog.csdn.net/qq_26003101/article/details/113606559