当我试图从登录表单后面抓取文本时,为什么会得到[]?

2024-09-27 19:25:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试通过“单击”查看新邮件“来刮取邮件。如果您想测试此收件箱,只需向以下地址发送电子邮件:“发件人:”Yopmail。但是,我只看到“[]”作为我的结果。我做错了什么?“[]”是什么意思?这是我的密码:

import requests
from bs4 import BeautifulSoup

# Start the session
session = requests.Session()

# Create the payload
payload = {'login':'1cdsjsdjkdfsnjsdfj42@yopmail.com', 
         }

# Post the payload to the site to log in
s = session.post("http://www.yopmail.com/en/", data=payload)

# Navigate to the next page and scrape the data
s = session.get('http://www.yopmail.com/en/')
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml' )
message = soup.find_all('div', class_='pdet nb')

print(message)

Tags: thetoimportcomhttpdatagetresponse
2条回答

首先,[]的意思是没有找到任何divs与这个特定的类

有一件事我认为可能是问题在于,你使用的是来自request.get(url)的响应,而不是来自session.get(...)。我想如果您只使用request.get(),您可能无法登录。 解决办法是使用soup = BeautifulSoup(s.text, 'lxml' )

但是如果这不起作用,错误可能是该类实际上没有div

尝试一步一步地打印每个变量的结果,以确保正确获取数据

可能会有一些问题,比如

可能无法获取数据 第页上没有div 无特定类别的div(pdet nb) 登录错误

请尝试打印soup变量以确保提取数据。如果未提取,请后退一步进行检查

相关问题 更多 >

    热门问题