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
from selenium import webdriver
from bs4 import BeautifulSoup
browser=webdriver.Firefox()
browser.get('http://webpage.com')
soup=BeautifulSoup(browser.page_source)
#do something useful
#prints all the links with corresponding text
for link in soup.find_all('a'):
print link.get('href',None),link.get_text()
假设您在要解析的页面上,Selenium将源HTML存储在驱动程序的
page_source
属性中。然后将page_source
加载到BeautifulSoup
中,如下所示:你确定要用硒吗?出于这个原因,我使用了PyQt4,它非常强大,你可以做任何你想做的事情。
我可以给你一个我刚刚写的示例代码,只要更改url,你就可以:
由于你的问题不是特别具体,这里有一个简单的例子。要做更有用的事情,请阅读BSdocs。您还可以在SO中找到大量使用硒(和BS)的示例。
相关问题 更多 >
编程相关推荐