0

I have following span tag. How can I scrape xuRMlBoIUcI7nAJktBcJvPByp1DLE4aPGzq3JNiRKsdNqUkVSJBY%2BggxRhp0GcRx4Gw4lWQxbTk%3D which is assigned to data-slug?

    <span data-ju-jspjrvxy="" 
    data-slug="xuRMlBoIUcI7nAJktBcJvPByp1DLE4aPGzq3JNiRKsdNqUkVSJBY%2BggxRhp0GcRx4Gw4lWQxbTk%3D" 
    data-gtm-clickedelement="CTA button" data-gtm-offer="" data-ju-wvxjoly-pk="303795"
 data-gtm-voucher-id="303795" class="businessinsiderus-voucher-button-holder clear">

        
Umair Mubeen
  • 823
  • 4
  • 22

3 Answers3

0

If s is your data string, then use the regex module:

import re
match = re.findall('data\-slug=\"()\"',str(s))
Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
0

If my understanding of your problem is correct you want to scrape an attribute of a tag. If this is in fact your problem the following link will provide a solution: Extracting an attribute value with beautifulsoup

PavelNikov
  • 48
  • 6
0
    from bs4 import BeautifulSoup as BS

    content = 'your html span text here'

    soup = BS(content,parser='html', features='lxml')

    dict_of_spantag_attributes_and_values = soup.span.attrs

    for i,j in dict_of_spantag_attributes_and_values.items():

        print(f'{i}:{j}')
yrnr
  • 71
  • 6