How to scrape, using LWP and a regex, the date argument to a javascript function?

前端 未结 1 1425
一生所求
一生所求 2021-01-21 14:29

I\'m having difficulty scraping dates from a specific web page because the date is apparently an argument passed to a javascript function. I have in the past written a few simpl

相关标签:
1条回答
  • 2021-01-21 15:00

    Why do you have two whitespace characters in your pattern?

    $content =~ s/.*dateFormat\('(\d{4}\/\d{2}\/\d{2}\s{2})'\);.*/$1/;
                                                     ^^^^^
    

    they are not in your format example 'dateFormat('2012/02/07')'

    I would say this is the reason why your pattern does not match.

    Capture all dates

    You can simply get all matches into an array like this

    ( my @Result ) = $content =~ /(?<=dateFormat\(')\d{4}\/\d{2}\/\d{2}(?='\))/g;
    

    (?<=dateFormat\(') is a positive lookbehind assertion that ensures that there is dateFormat\(' before your date pattern (but this is not included in your match)

    (?='\)) is a positive lookahead assertion that ensures that there is '\) after the pattern

    The g modifier let your pattern search for all matches in the string.

    0 讨论(0)
提交回复
热议问题