首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用webbot进行Web抓取

使用webbot进行Web抓取
EN

Stack Overflow用户
提问于 2019-12-29 06:14:35
回答 1查看 976关注 0票数 0

我正在尝试创建一个简单的程序,使用我的凭证登录到一个网页,并获取我在我的大学账户中剩余的弹性美元总额。从登录页面开始,我登录,并被重定向到感兴趣的页面,我只是想获取美元金额并对其执行一些操作。

我目前正在使用webbot进行登录,这是可行的,我刚刚编辑了凭据:

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-29 10:00:24

您首先需要获取当前网页的html源代码。您可以使用get_page_source()来做到这一点。然后,您需要将html源代码传递给beautifulsoup

代码语言:javascript
复制
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")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59515319

复制
相关文章

相似问题

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