【发布时间】:2019-01-11 20:52:16
【问题描述】:
我对scrapy 比较陌生,我想知道是否有办法将引荐来源网址传递给response.follow() 命令。我正试图从满是网站的手中刮取房地产土地价格,但我很难按照分页链接进行抓取。刮板在主页上工作正常,但该网站不允许它访问任何其他页面。
我尝试在 scrapy shell 中使用 fetch 命令直接打开第二页,但没有成功。我使用视图打开页面检查元素,发现以下错误:
“CORS 策略已阻止从源 'null' 访问位于 'https://someaddress.com 的 XMLHttpRequest:请求的资源上不存在 'Access-Control-Allow-origin' 标头。”
任何建议或资源将不胜感激。
-谢谢
import scrapy
class cwSpider(scrapy.Spider):
name = 'cushman2'
custom_settings = {
'DUPEFILTER_DEBUG': 'True',
}
start_urls = ['https://cwstevenson.ca/properties/advance-search-properties/']
def parse(self, response):
# follow links to author pages
for href in response.css('.wpl_prp_bot a::attr(href)'):
yield response.follow(href, self.parse_property)
# follow pagination links
for href in response.css('li.next a::attr(href)'):
yield response.follow(href, self.parse)
def parse_property(self, response):
response.request.headers.get('Referrer', None)
def extract_with_css(query):
return response.css(query).extract()
yield {
'address' : extract_with_css('h1.title_text::text'),
'Prop_Type': extract_with_css('.ldetailscont2 p.ldetailsinfo::text')[0],
'Land Area': extract_with_css('.ldetailscont2 p.ldetailsinfo::text')[1],
'Price': extract_with_css('.ldetailscont2 p.ldetailsinfo::text')[2],
'Listing_Type': extract_with_css('.ldetailscont2 p.ldetailsinfo::text')[3],
'Area_Avail': extract_with_css('.ldetailscont2 p.ldetailsinfo::text')[4],
'Prop_Taxes': extract_with_css('.ldetailscont2 p.ldetailsinfo::text')[5],
}
【问题讨论】:
标签: python web-scraping scrapy http-status-code-301 referrer