我正在尝试创建一个简单的程序,使用我的凭证登录到一个网页,并获取我在我的大学账户中剩余的弹性美元总额。从登录页面开始,我登录,并被重定向到感兴趣的页面,我只是想获取美元金额并对其执行一些操作。
我目前正在使用webbot进行登录,这是可行的,我刚刚编辑了凭据:
from webbot import Browser
web = Browser()
web.go_to('insert my url here')
#enter your username and password in the into fields below
web.type('insert email here', into='username')
web.type('insert password here', into='password')
web.click('Login', tag='span')到目前为止,这个方法工作得很好,创建了一个Chrome实例,并登录到我想要从中获取美元金额的页面。我想我可能想继续使用urllib,然而,我不认为urllib会从我当前登录的Chrome实例中受益。我如何解决这个问题,并从页面中获取一个简单的html元素?
发布于 2019-12-29 10:00:24
您首先需要获取当前网页的html源代码。您可以使用get_page_source()来做到这一点。然后,您需要将html源代码传递给beautifulsoup
from webbot import Browser
from bs4 import BeautifulSoup
import time
web = Browser()
web.go_to('insert my url here')
#enter your username and password in the into fields below
web.type('insert email here', into='username')
web.type('insert password here', into='password')
web.click('Login', tag='span')
time.sleep(5)
content = web.get_page_source()
soup = BeautifulSoup(content)
#You can now find the element you want
samples = soup.find_all("a", "item-title")https://stackoverflow.com/questions/59515319
复制相似问题