如何使用只包含匿名密码字段的登录表单来创建特定的网页,然后将值提交给ajax?用硒?

2024-09-30 05:26:38 发布

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

我是Python Scrapy的新手,到目前为止:

import scrapy

class ExampleSpider(scrapy.Spider):
    name = 'example'
    allowed_domains = ['flashfurniture.com']
    start_urls = ['http://flashfurniture.com/']

    skus = ['LE-L-C-BLACK-GG', 'SZ-TUFT-SIL-GG']
    zips = ['33122', '90210', '07501', '60007']
    qtys = [1, 2, 12, 24, 50]

    def start_requests(self):
        for sku in self.skus:
            yield scrapy.Request(url='http://www.flashfurniture.com/'+sku.lower()+'.html', cookies=[{'name': 'password', 'value': 'fubar', 'domain': 'www.flashfurniture.com', 'path': '/'}], callback=self.parse)

    def parse(self, response):
        sku = response.css('#fobTable .product-code::text').extract_first()
        self.log(sku)
        for zip in self.zips:
            for qty in self.qtys:
                return scrapy.FormRequest(url=response.url, formdata={'vwquantity': str(qty), 'shippingAddressDS.shipping_ROW0_zip': zip}, callback=self.after_post)
                #self.log('LTL FDX')
                #pass #write to file

    def after_post(self, response):
        LTL = response.css('#calcBox .unique-shipment #rateRad0[value]::text').extract_first()
        FDX = response.css('#calcBox .unique-shipment #rateRad1[value]::text').extract_first()
        self.log('LTL $%s FDX $%s' % (LTL, FDX))
        self.log(response.xpath('//div[@class="show-button"][@style]'))

上面返回SKU(非常正确)和

2017-12-18 14:28:51 [example] DEBUG: LTL $None FDX $None
2017-12-18 14:28:51 [example] DEBUG: []
2017-12-18 14:28:51 [example] DEBUG: LTL $None FDX $None
2017-12-18 14:28:51 [example] DEBUG: []

最后一行应该是登录成功测试。你知道吗

请注意,我上面代码中包含的密码是无效的;希望您能帮助我解决这个问题。你知道吗

我试图实现的目标应该非常清楚:我最终需要为每个SKU/解析的页面写入CSV五行,以包含以下内容:

SKU, Z0Q0L, Z0Q0F, Z1Q0L, Z1Q0F, Z2Q0L, Z2Q0F, Z3Q0L, Z3Q0F Q1, Z0Q1L, Z0Q1F, Z1Q1L, Z1Q1F, Z2Q1L, Z2Q1F, Z3Q1L, Z3Q1F Q2, Z0Q2L, Z0Q2F, Z1Q2L, Z1Q2F, Z2Q2L, Z2Q2F, Z3Q2L, Z3Q2F Q3, Z0Q3L, Z0Q3F, Z1Q3L, Z1Q3F, Z2Q3L, Z2Q3F, Z3Q3L, Z3Q3F Q4, Z0Q4L, Z0Q4F, Z1Q4L, Z1Q4F, Z2Q4L, Z2Q4F, Z3Q4L, Z3Q4F

其中QN=qty[]表示值的索引,例如z0q0l=rateRad0(LTL)返回的值,第一个zip(33122)和第一个qty(1)。你知道吗

我需要计算100+产品的每种组合的运费,请帮助。非常感谢。你知道吗

我认为应该合并Selenium,但不确定如何实现。你知道吗


Tags: debugselfcomnonelogexampleresponsedef
1条回答
网友
1楼 · 发布于 2024-09-30 05:26:38

编写代码以HTML格式保存响应体对象。如果所需对象在下载的HTML文件中,那么请检查XPath/CSS选择器,如果不是,则可能是因为AJAX调用,要解决此问题,请使用SplahRequest而不是皮屑。请求你知道吗

相关问题 更多 >

    热门问题