gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
用scrapy框架从网址'https://www.weather.com.cn/textFC/chongqing.shtml'爬取重庆及各区县的天气预报,给出具体代码
- User
- Assistant
下面给出了使用Scrapy框架爬取重庆市及各区县天气预报的具体代码:
pythonimport scrapy class WeatherSpider(scrapy.Spider): name = "weather" start_urls = [ 'https://www.weather.com.cn/textFC/chongqing.shtml' ] def parse(self, response): district_nodes = response.xpath('//div[@class="conMidtab"][1]//tr[@class=""]') for node in district_nodes: district_name = node.xpath('.//td[1]/a/text()').get() district_temperature = node.xpath('.//td[2]/text()').get() district_weather = node.xpath('.//td[3]/text()').get() yield { 'district_name': district_name, 'district_temperature': district_temperature, 'district_weather': district_weather }