我怎样才能解析使用Python中硒和Beautifulsoup一个网站吗? [英] How can I parse a website using Selenium and Beautifulsoup in python?

查看:91
本文介绍了我怎样才能解析使用Python中硒和Beautifulsoup一个网站吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的编程和想出如何定位到我需要用Selenium去。我想,但现在不知道解析数据从哪里开始。有人能握住我的手一秒钟,点我在正确的方向?

New to programming and figured out how to navigate to where I need to go using Selenium. I'd like to parse the data now but not sure where to start. Can someone hold my hand a sec and point me in the right direction?

任何帮助AP preciated -

Any help appreciated -

推荐答案

假设你是要分析在页面上,硒存储HTML源在驱动程序的 page_source 属性。这样,你会加载 page_source BeautifulSoup 如下:

Assuming you are on the page you want to parse, Selenium stores the source HTML in the driver's page_source attribute. You would then load the page_source into BeautifulSoup as follows:

In [8]: from bs4 import BeautifulSoup

In [9]: from selenium import webdriver

In [10]: driver = webdriver.Firefox()

In [11]: driver.get('http://news.ycombinator.com')

In [12]: html = driver.page_source

In [13]: soup = BeautifulSoup(html)

In [14]: for tag in soup.find_all('title'):
   ....:     print tag.text
   ....:     
   ....:     
Hacker News

这篇关于我怎样才能解析使用Python中硒和Beautifulsoup一个网站吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆