繁体   English   中英

我用 BeautifulSoup 找不到信息

[英]I can't find information with BeautifulSoup

我想对 url 进行网络抓取,但是当我使用 BeautifulSoup 时,找不到我正在查找的某些信息,但它们在原始 html 中。 如果打印(html_page),我有我需要的所有信息,但是当它出现输出时,没有信息,当我尝试直接在 html_page 上搜索时,会发生此错误:

word = html_page  
word.find('name="produto-stock"')               
TypeError: argument should be integer or bytes-like object, not 'str'

我的代码

import requests
from bs4 import BeautifulSoup

url = 'https://www.maze.com.br/produto/tenis-puma-suede-classic-azul-marinho/4513515'

res = requests.get(url)
html_page = res.content
soup = BeautifulSoup(html_page, 'html.parser')
text = soup.find_all(text=True)

output = ''
blacklist = [
    'noscript',
    'header',
    'html',
    'meta',
    'head', 
    'input',
    'script',

]

for t in text:
    if t.parent.name not in blacklist:
        output += '{} '.format(t)
    
word = output
word.find('produto-stock')

为什么用引号括起来,删除它们:-(

word = html_page
word.find("produto-stock")

我做了这个更改,但错误仍然发生:参数应该是整数或类似字节的对象,而不是“str”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM