python - 如何在当前 Firefox/Mozilla 实例中从新窗口中抓取?
问题描述
我可以在 Firefox/Mozilla 中打开一个新选项卡,抓取内容,然后将大量文本写入文件,就像这样。
from bs4 import BeautifulSoup
import requests
import urllib.request
import webbrowser
url = 'https://console.cloud.google.com/'
webbrowser.open_new_tab(url)
r=requests.get(url)
data = r.text
print(data)
soup = BeautifulSoup(data, 'html.parser')
file = open('C:\\path_here\\test.txt', 'w')
file.write(data)
file.close()
问题是我只从网站中获取一小部分文本到文本文件中。如何将站点中的所有文本转储到文件中?我猜某些内容必须是动态生成的,否则所有内容都会转储到文本文件中。我可以看出该站点中有一个 JavaScript 组件,但我不确定如何利用它。
解决方案
如何使用硒:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://console.cloud.google.com/')
browser.page_source
推荐阅读
- python - 从结构不同的名称冲突包中导入?
- c++ - 向量索引变量声明(size_t 或 std::vector
::尺码类型) - kubernetes - 默认 StorageClass:检查什么?
- python - 解决后使功能不可用?
- javascript - 与本机消息传递主机 - Java 通信时出错
- amazon-web-services - 路径前的 API Gateway cloudformation 方法
- automation - 插件录音机和录音有什么区别?
- powershell - 自动登录到 msonline 和 azuread 模块 - 可能吗?
- c - 无法覆盖返回地址(eip)
- php - 我如何在php中相应地交织2个变量?