python - 使用python使用scrapy splash同时抓取多个不同的url
问题描述
我需要同时使用scrapy和splash来抓取多个网址。我尝试编写以下代码,但仍然没有运气。
我已经附上了网址。。这里..
'https: //wunderground.com/forecast/us/ny/布鲁克林
/','https://www.wunderground.com/forecast/us/pa/california/','https://www.wunderground.com/forecast/us/ny/boston
'
所以我需要遍历这些 URL,然后使用 scrapy 抓取它。
我无法使用多 url 获取数据。它显示错误。请帮助
我的问题是如何进一步抓取此 URL 列表?
import scrapy
from scrapy_splash import SplashRequest
import scrapy_proxies
class WundergroundSpider(scrapy.Spider):
name = 'wunderground'
#allowed_domains = ['www.wunderground.com/forecast/us/ny/brooklyn']
start_urls = []
script = '''
function main(splash, args)
splash.private_mode_enabled = false
assert(splash:go(args.url))
assert(splash:wait(10))
return splash:html()
end
'''
def start_requests(self):
urls = [
'https://wunderground.com/forecast/us/ny/brooklyn/',
'https://www.wunderground.com/forecast/us/pa/california/',
'https://www.wunderground.com/forecast/us/ny/boston'
]
for url in urls:
yield SplashRequest(url, self.parse, args={'wait': 8})
def parse(self, response):
tmps= {
'tempHigh': response.xpath("//div[@class='forecast']/a[@class='navigate-to ng-star-inserted']/div[@class='obs-forecast']/span/span[@class='temp-hi']/text()")[0],
'templow': response.xpath("//div[@class='forecast']/a[@class='navigate-to ng-star-inserted']/div[@class='obs-forecast']/span/span[@class='temp-lo']/text()")[0],
'obsphs' : response.xpath("//div[@class='forecast']/a[@class='navigate-to ng-star-inserted']/div[@class='obs-forecast']/div[@class='obs-phrase']/text()")[0]
}
yield tmps
解决方案
推荐阅读
- python - 在打印的表格中使用美元值中的逗号
- sql - 仅当布尔值为真时才加入
- c++ - 将字符串解析为 C++ 的数组
- javascript - 在 Gatsby 中设置布局
- python - OANDA 不推荐使用的 REST API
- python - 如果可能的话,如何获得所需的迭代次数来获得数组的 2 个元素?
- docker - 套接字:grafana docker的权限被拒绝
- python - 如何设置从 json 对象传递的函数参数?
- python - 如何在单独的函数中更新两个数组的多个连接,当一个的大小是有条件的,而另一个是恒定的
- javascript - 如果另一个元素具有活动类,则添加类,如果不使用 javascript/JQuery,则将其删除