嗨,我在如何使用bs4返回方面遇到了困难(我特别希望bs4位于HTML的最底层)
任何想法/解决方案都是非常感谢的。
这是完整的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 & Sell now using Europes most trusted online Sneakers & 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 & Sell now using Europes most trusted online Sneakers & 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==" />我成功地做到了,但是以一种非常复杂的方式,我无法返回令牌的值,这是我需要用来登录的
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)发布于 2022-09-27 12:02:10
您可以像这样搜索name="csrf-token":
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)输出:
0HFqDSNx1c+1PUW36nrGLwuuVaYMDNWNa22trb7vXbIEGrFOizBtxVH/1z1UKG0DWMU9HcZOVHyTU//XVyLTpw==https://stackoverflow.com/questions/73867135
复制相似问题