How to isolate this data in BeautifulSoup4?

Question:

Hi I am having trouble on how to use bs4 to return (I specifically want ‘0HFqDSNx1c+1PUW36nrGLwuuVaYMDNWNa22trb7vXbIEGrFOizBtxVH/1z1UKG0DWMU9HcZOVHyTU//XVyLTpw==’ located on the very bottom of the HTML)

Any ideas/solutions would be great thanks

Here is the full HTML

    <!DOCTYPE html>
<html lang="en">
  <head>
  <title>Trainers, Sneakers, Buy and sell Sneakers and Trainers Online | Laced</title>
  <!-- Metadata -->
  <meta name="robots" content="follow, index" />
  <meta name="viewport" content="initial-scale=1, maximum-scale=5, width=device-width">
  <meta name="description" content="Check out the latest Trainers and Sneakers on Laced. We have a great selection of Authentic Yeezy Trainers and sneakers, Nike Jordans and many more brands. Buy &amp; Sell now using Europes most trusted online Sneakers &amp; Trainers website.">
  <meta name="keywords" content="Laced, Laced UK, Online Trainer store, Online Sneaker store, Laced.co.uk">
    <meta property="og:url" content="https://www.laced.co.uk/">
  <meta property="og:type" content="website">
  <meta property="og:title" content="Trainers, Sneakers, Buy and sell Sneakers and Trainers Online | Laced">
  <meta property="og:image" content="https://www.laced.co.uk/assets/logo-e9aeb99a105b263f01aba655753d465459ae18b742986cd34edacd57f271808c.png">
  <meta property="og:description" content="Check out the latest Trainers and Sneakers on Laced. We have a great selection of Authentic Yeezy Trainers and sneakers, Nike Jordans and many more brands. Buy &amp; Sell now using Europes most trusted online Sneakers &amp; Trainers website.">
  <meta property="fb:app_id" content="369928193727220">
  <meta name="twitter:card" content="summary">
  <meta name="twitter:site" content="@lacedhq" />
  <meta name="twitter:creator" content="@lacedhq" />

    <link rel="canonical" href="https://www.laced.co.uk/" />

  <script>
    history.scrollRestoration = 'manual'
  </script>

  <link rel="icon" type="image/png" href="https://www.laced.co.uk/assets/favicon-30717de857f7ebb6f1110443a66a8e4d2383e5d2adb240afe5c51d5ad1dd88d6.png" />
  <meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="0HFqDSNx1c+1PUW36nrGLwuuVaYMDNWNa22trb7vXbIEGrFOizBtxVH/1z1UKG0DWMU9HcZOVHyTU//XVyLTpw==" />

I’ve managed to do it but in a very complicated way and I can’t return the value of the token which is what I need to use to log in

s = requests.Session()
response = s.get(url)

soup = bs(response.text, 'html.parser')
meta = soup.find_all('meta')

for i in meta[14:15]:
    token = i['content']
    print(token)
Asked By: Ruibin Wu

||

Answers:

You can search for name="csrf-token" like so:

from bs4 import BeautifulSoup

html = """
OP's HTML
"""

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

meta = soup.find('meta', {'name': 'csrf-token'})
meta = meta['content']

print(meta)

Output:

0HFqDSNx1c+1PUW36nrGLwuuVaYMDNWNa22trb7vXbIEGrFOizBtxVH/1z1UKG0DWMU9HcZOVHyTU//XVyLTpw==
Answered By: 0stone0