Scrapy FormRequest的多个按钮

时间:2019-03-17 12:37:46

标签: python forms button scrapy python-requests

我正在尝试从表单中获取第二个按钮,但似乎无法正确获取FormRequest。

这是表单的HTML代码:

<form action="/search/misc/set_serp_view" method="POST" class="btn-group">
        <button class="btn btn-white active" type="submit" name="serp_view" value="serp-cards">
            <i class="fa fa-usd"></i> Prices
        </button>
        <button class="btn btn-white " type="submit" name="serp_view" value="serp-grid">
            <i class="fa fa-table"></i> Specs
        </button>
    </form>

我使用了这段代码,

class ProductSpider(scrapy.Spider):
    name='nameCode'
    start_urls = ['https://octopart.com/electronic-parts/integrated-circuits-ics' ]

    def parse(self,response):
        return FormRequest.from_response(response, formxpath="//form[@class='btn-group']/button[@value='serp-grid']",callback = self.scrape_pages)

    def scrape_pages(self,response):
        open_in_browser(response)        

,但默认情况下会选择 serp-cards

1 个答案:

答案 0 :(得分:1)

这就像魅力

    <Datatable

       options={{
       data: {blogs && blogs},
       columns: [
       {data: "title"},
        {data: "author"},
        {data: "viewers"},
      ]
 }}