刚接触编程,并想出了如何使用 Selenium 导航到我需要去的地方。我现在想解析数据,但不知道从哪里开始。有人可以握住我的手并指出正确的方向吗?
任何帮助表示赞赏 -
最佳答案
假设您在要解析的页面上,Selenium 将源 HTML 存储在驱动程序的 page_source
属性中。然后将 page_source
加载到 BeautifulSoup
中,如下所示:
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://news.ycombinator.com')
html = driver.page_source
soup = BeautifulSoup(html)
for tag in soup.find_all('title'):
print(tag.text)
Hacker News
关于python - 如何在 python 中使用 Selenium 和 Beautifulsoup 解析网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13960326/