首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在BeautifulSoup4中隔离这些数据?

如何在BeautifulSoup4中隔离这些数据?
EN

Stack Overflow用户
提问于 2022-09-27 11:53:51
回答 1查看 29关注 0票数 0

嗨,我在如何使用bs4返回方面遇到了困难(我特别希望bs4位于HTML的最底层)

任何想法/解决方案都是非常感谢的。

这是完整的HTML

代码语言:javascript
复制
    <!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==" />

我成功地做到了,但是以一种非常复杂的方式,我无法返回令牌的值,这是我需要用来登录的

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-27 12:02:10

您可以像这样搜索name="csrf-token"

代码语言:javascript
复制
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)

输出:

代码语言:javascript
复制
0HFqDSNx1c+1PUW36nrGLwuuVaYMDNWNa22trb7vXbIEGrFOizBtxVH/1z1UKG0DWMU9HcZOVHyTU//XVyLTpw==
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73867135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档