向下滚动时的响应url为:
响应数据在ajax中的格式如下:
{"page_var":"<div id=\"page_variables................
我的蜘蛛代码是:
import scrapy
class DummymartSpider(scrapy.Spider):
name = 'dummymart'
allowed_domains = ['dir.dummymart.com']
start_urls = ['https://dir.dummymart.com/impcat/industrial-machinery.html',
]
def parse(self, response):
Company = response.xpath('//*[@class="lcname"]/text()').extract()
product = response.xpath('//*[@class="pnm ldf cur"]/text()').extract()
address = response.xpath('//*[@class="clg"]/text()').extract()
phone = response.xpath('//*[@class="ls_co phn bo"]/text()').extract()
for item in zip(Company,product,address,phone):
scraped_info = {
'Company':item[0],
'Product': item[1],
'Address':item[2],
'phone':item[3]
}
yield scraped_info
如何在向下滚动页面后刮取加载的数据?此外,数据是ajax格式的,而不是json格式的。谢谢
您可以采用两种方法:- 1.使用像Selenium这样的无头浏览器,或者如果您在Scrapy中工作,那么您也可以尝试Splash,它允许您通过Scrapy运行js函数。 2.只需将页面滚动到要删除数据的位置,将该页面下载为HTML,然后运行普通代码
第二种方法是小手册,但如果你只想废弃几页,那么我建议你只使用后一种方法
相关问题 更多 >
编程相关推荐