python - 如何通过更改 yield SplashRequest 的代码将 URL 从 A 的方法传递给 B?(Scrapy + Splash with Python & Dcoker)
问题描述
###########这篇文章是在我发现它之前发布的没有我想要的数据。这就是为什么我尝试另一种方法来利用硒或其他东西。谢谢!!【我想知道的:如何修改yield SplashRequest(url, callback=self.parse, args = {"wait": 5}, endpoint = "render.html")的代码】</p>
我不知道我应该更改代码以便在使用scrapy + splash的情况下将URL从A的方法传递到B的方法。
在我看来,更正的地方是,
yield SplashRequest(url, callback=self.parse, args = {"wait": 5}, endpoint = "render.html")
start_requests 方法(#1)。
有3个原因。
第一个原因是,
“yield SplashRequest(url, callback=self.parse, args = {"wait": 5}, endpoint = "render.html")" 之前的 logging.info(#2) 给了我正确的反馈。
第二个原因是,
我设置了scrapy + splash,阅读了Scrapy + Splash的自述文件作为参考。
用于 JavaScript 集成的 Scrapy+Splash https://github.com/scrapy-plugins/scrapy-splash
第三个原因是,
记录方法(#3)没有给我任何信息。这是我的代码。
# -*- coding: utf-8 -*-
import scrapy
from scrapy_splash import SplashRequest
from bnb_sentiment.items import BnbItem
from scrapy_splash import SplashRequest
import re
import logging
logging.basicConfig(level=logging.INFO)
# __name__ is name of a method
logger = logging.getLogger(__name__)
class BnbPriceTestSpider(scrapy.Spider):
name = 'bnb_price_test'
start_urls = [
# Tokyo--Japan
'https://www.airbnb.com/s/Tokyo--Japan/homes?refinement_paths%5B%5D=%2Fhomes&allow_override%5B%5D=&checkin=2018-07-07&checkout=2018-07-08&locale=en&min_beds=0&price_max=20000&price_min=10000&query=Tokyo%2C%20Japan&place_id=ChIJ51cu8IcbXWARiRtXIothAS4&s_tag=Mz88jJs1',
]
def start_requests(self):
for url in self.start_urls:
logger.info(url) #2
yield SplashRequest(url, callback=self.parse, args = {"wait": 5}, endpoint = "render.html") #1
def parse(self, response):
for href in response.xpath('//div[contains(@id, "listing-")]//a[contains(@href, "rooms")]/@href'):
import pdb; pdb.set_trace()
logger.info(href)
url = response.urljoin(href.extract())
import pdb; pdb.set_trace()
logger.info(url) #3
yield SplashRequest(url, callback=self.parse_scrape)
def parse_scrape(self, response):
pass
(#2) 这里是记录方法的反馈。
/home/ubuntu/bnbsp/bnb_sentiment/bnb_sentiment/spiders/bnb_price.py(34)start_requests() -> logger.info(url) *1 (Pdb) url 'url 与 start_urls 相同'
解决方案
推荐阅读
- spring-security-oauth2 - Spring Cloud 合约 jwt 代币
- python - 如何在 4 维 numpy 数组中合并多个 3 维 numpy 数组?
- c# - 当我释放第二次触摸时,Unity Input Touch 也会取消第一次触摸
- recurrent-neural-network - 什么是滚动 RNN?
- sql - 尝试添加一个按 ID 映射回来的数据 ID 列
- safari - Safari 14 WebGL alpha 与帧缓冲渲染的混合似乎被破坏了
- python - 有没有高级的 pySD 教程?
- r - 编写一个将变量捆绑为一个的函数
- ios - Core Data model attribute types not compatible with program types
- node.js - Mongoose 查询文档、处理结果然后删除的最佳方法?