第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Scrapy:如何從頁面上的所有選項卡獲取信息?

Scrapy:如何從頁面上的所有選項卡獲取信息?

慕尼黑5688855 2023-08-29 18:08:52
在此頁面上,我需要從所有選項卡(個人資料、評論、電話號碼和方向)獲取信息。wellness.pydef profile(self, response):    services = response.xpath('.//span[contains(text(),"Services")]')    education = response.xpath('.//span[contains(text(),"Education")]')    training = response.xpath('.//span[contains(text(),"Training")]')    yield {            'First and Last name': response.css('h1::text').get(),            'About': response.css('.listing-about::text').get(),            'Services': services.xpath('following-sibling::span[1]/text()').extract(),            'Primary Specialty': response.css('.normal::text').get(),            'Address': ' '.join([i.strip() for i in response.css('.office-address span::text').getall()]),            'Practice': response.css('.years-in-service::text').get(),            'Education': education.xpath('following-sibling::span[1]/text()').extract(),            'Training': training.xpath('following-sibling::span[1]/text()').extract(),            'Consumer Feedback': response.css('.item-rating-container a::text').get()                        }
查看完整描述

1 回答

?
波斯汪

TA貢獻1811條經驗 獲得超4個贊

每個選項卡都加載一個單獨的頁面/url。我想你認為既然它被標記為同一頁面。因此,您必須從第一頁收集所需的數據,請求第二頁獲取數據,然后請求第三頁。您可以通過在元屬性中傳遞項目來保留上一頁的數據。我就是這樣做的。請注意,鏈接的代碼是正確的,您必須為每個頁面上的數據點創(chuàng)建選擇器。


def profile(self, response):

    item = {}

    item["field1"] = response.xpath('//xpath').get()

    # Get first link for reviews

    review_link = response.css('#reviews_tab a::attr(href)').get()

    yield scrapy.Request(response.urljoin(review_link), callback=self.parse_reviews, meta={'item': item})


def parse_reviews(self, response):

    item = response.meta['item']

    item["field2"] = response.xpath

    directions_link = response.css('#directions_tab a:attr(href)').get()

    yield scrapy.Request(response.urljoin(directions_link), callback=self.parse_directions, meta={'item': item})


def parse_directions(self, response):

    item = response.meta['item']

    item['directions'] = response.xpath

    yield item


查看完整回答
反對 回復 2023-08-29
  • 1 回答
  • 0 關注
  • 160 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號