Scrapy: Extract commented (hidden) content

后端 未结 2 1865
旧巷少年郎
旧巷少年郎 2021-01-03 06:07

How can I extract content from within commented tags with scrappy ?

For instance, how to extract \"Yellow\" in the following example:

2条回答
  •  情歌与酒
    2021-01-03 06:24

    First of all, use below xpath to get all the comments from the page.

    data = response.xpath('//comment()').extract()
    

    Now, using any key value identity your meaning comments.

    up_data = []
    for d in data:
        if 'key' in d:
            up_data.append(d)
    

    define,

    html_template = '%s'
    for up_d in up_data:
        up_d = html_template % up_d.replace('', '')
        sel = Selector(text=up_d)
        sel.xpath('//div[@class="table_outer_container"]')
    
        // DO what you want
    

提交回复
热议问题