从“”获取数据https://realtruck.com/p/ruggedridgefloormats/“使用Python Scrapy

2024-10-03 11:15:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从“https://realtruck.com/p/rugged-ridge-floor-mats/”获取数据 但问题是他们改变了布局。 现在我试着得到下拉列表

enter image description here

问题:列表很灵活,一次可能有5个列表,10个我们不知道的列表。 所以我想要根据下拉列表灵活的for循环

这是我以前的代码: 这是静态代码,我希望它是动态的

 for year in years: 
      yield ... 
      make_arr  

      for make in make_arr:     
         yield ...      
         models_arr     

         for model in models_arr:           
           yield ...            
           body_arr 
            for body in body_arr:       
                yield ...
                colors_arr                  
                for color in colors_arr:    
                    yield ...

Tags: 代码inhttpscom列表formakemodels
1条回答
网友
1楼 · 发布于 2024-10-03 11:15:26

这些列表是动态的(年份除外),它们的数据是使用XHR调用填充的

HTTP POST https://uwp.thiecommerce.com/uwp-v3/rt/ordercontrols/rugged-ridge-floor-mats

post有效负载包括用户以前的选择。示例

{"year":2018,"makeSlug":"chevy"}

因此,您需要多年来循环并开始调用XHR调用。在这个循环中,您需要为每个子类别嵌套更多的循环

比如:

for years in [2017,2018] # more years goes here
    #get the year Make list
    for make in makes:
        #get the make Model list
        for model in models:
            # get the model body list
            for body in bodies:
                #  call https://uwp.thiecommerce.com/uwp-v3/rt/recs/similar/? 
                        makeSlug=chevy&modelSlug=silverado- 
                        1500&year=2017&bodySlug=crew-cab&productLineSlug=rugged- 
                        ridge-floor-mats
                # and you will have the data

相关问题 更多 >