0

How the take just "data-ds-appid"?

<a href="https://store.steampowered.com/app/730/CounterStrike_Global_Offensive/?snr=1_241_4_action_104" class="tab_item  "  data-ds-appid="730" data-ds-itemkey="App_730"

Thanks in advance!

karel
  • 5,489
  • 46
  • 45
  • 50
Burak
  • 37
  • 6
  • Can you clarify what the issue is? – AMC Mar 20 '20 at 18:50
  • I just want to take "data-ds-appid =" 730" --------- soup.findAll(class_="tab_item", attrs={"data-ds-appid"} this code take all html block. – Burak Mar 20 '20 at 18:54
  • Alright, so which part are you struggling with? Have you tried anything, done any research? Have you read the BeautifulSoup docs? – AMC Mar 20 '20 at 18:58
  • I read the documents, but I couldn't find anything about it. – Burak Mar 20 '20 at 19:00
  • _I read the documents, but I couldn't find anything about it._ How is that possible? – AMC Mar 20 '20 at 21:13
  • Does this answer your question? [Extracting an attribute value with beautifulsoup](https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup) – AMC Mar 20 '20 at 21:13

1 Answers1

1

You can access a tag’s attributes by treating the tag like a dictionary 1

from bs4 import BeautifulSoup

data = '''<h1>asdfas</h1>
<p>asd aasdfas dfasd
<a href="https://store.steampowered.com/app/730/CounterStrike_Global_Offensive/?snr=1_241_4_action_104" class="tab_item  "  data-ds-appid="730" data-ds-itemkey="App_730">asdfas</a>
</p>
'''

soup = BeautifulSoup(data, 'html.parser')

idlist = [element['data-ds-appid'] for element in soup.find_all(class_="tab_item")]

print(idlist)
  • https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup – AMC Mar 20 '20 at 21:14