【发布时间】:2022-07-06 03:56:08
【问题描述】:
我不知道如何抓取ajax页面网站上没有分页点击load more button将加载网站这些是页面链接https://aaos22.mapyourshow.com/8_0/explore/exhibitor-gallery.cfm?featured=false
import scrapy
from scrapy.http import Request
from selenium import webdriver
from scrapy_selenium import SeleniumRequest
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):
title = response.css(".mr3-m::text").get()
address = response.css(".showcase-address::text").get()
address=address.strip()
website = response.xpath("//li[@class='dib ml3 mr3']//a[starts-with(@href, 'http')]/@href").get()
website=website.strip()
phone = response.xpath("//li[@class='dib ml3 mr3'] //span[contains(text(), 'Phone:')]/following-sibling::text()").get()
phone=phone.strip().replace("-","")
yield{
'title':title,
'address':address,
'website':website,
'phone':phone
}
【问题讨论】:
-
那么你到底卡在什么地方了?点击加载更多结果按钮?
-
是的,当我单击它们显示结果时,我被困在
Load More Results button,但我不知道如何从中抓取数据 -
你想抓取哪些信息?
-
titleaddresswebsitephone -
我也没有看到你在代码试验中抓取
title、address、website、phone。
标签: python selenium web-scraping scrapy