Home > Net >  Xpath give nothing
Xpath give nothing

Time:07-06

I am getting trying to getting phone number but give nothing from the xpath how to solve these problem these is page link https://aaos22.mapyourshow.com/8_0/exhibitor/exhibitor-details.cfm?exhid=999999999999

import scrapy
from scrapy.http import Request
from bs4 import BeautifulSoup
from selenium import webdriver
import time
from scrapy_selenium import SeleniumRequest
import requests
import json
import pandas  as pd

class TestSpider(scrapy.Spider):
    name = 'test'
    
    
    def start_requests(self):
        yield SeleniumRequest(
            url="https://aaos22.mapyourshow.com/8_0/explore/exhibitor-gallery.cfm?featured=false",
            wait_time=3,
            screenshot=True,
            callback=self.parse,
            dont_filter=True
        )
        
    
    
    def parse(self, response):
        books = response.xpath("//h3[@class='card-Title\nbreak-word\nf3\nmb1\nmt0']//a//@href").extract()
        
        for book in books:
            url = response.urljoin(book)
            yield Request(url, callback=self.parse_book)
            
    def parse_book(self, response):
        
        phone = response.xpath("//li[@class='dib  ml3  mr3'][2]").get()
        print(phone)

CodePudding user response:

Assuming you get the concret HTML you could adjust your xpath - Select the <ul> by its class and the last <li>. Cause the number is not included in the <span>, you have to call its sibling:

//ul[contains(@class,'showcase-web-phone')]/li[last()]/span/following-sibling::text()[1]

CodePudding user response:

If you want to get rid of indexing, this is how you can achieve that:

response.xpath("normalize-space(//*[starts-with(@class,'showcase-web-phone')]/li[./*[.='Phone:']]/span/following::text())").get()
  • Related