XPath一无所获
我正在尝试获取电话号码
,但是从XPath中什么都没有解决这些问题。 -details.cfm?eunid = 99999999999“ rel =” nofollow noreferrer”> https://aaos22.mapyourshow.com/8_0/exhibitor/exhibitor/exhibitor-details.cfm?exhid=9999999999999
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您获得Concret
HTML
可以调整XPATH
- 通过其< ul>
通过其class> class
和最后一个< li>
。因为该号码不包含在< span>
中,您必须调用其sibling
:Assuming you get the concret
HTML
you could adjust yourxpath
- Select the<ul>
by itsclass
and the last<li>
. Cause the number is not included in the<span>
, you have to call itssibling
:如果您想摆脱索引,这就是您可以实现这一目标的方法:
If you want to get rid of indexing, this is how you can achieve that: