python - 即使在使用铬之后,抓取 JS 也失败了
问题描述
我正在尝试抓取这个网站:
我试过这个:
first_fallen_url = r'https://www.izkor.gov.il/%D7%90%D7%94%D7%A8%D7%95%D7%9F%20%D7%94%D7%A8%D7%A9%D7%9C%D7%A8/en_399451c07d6af2edbb259e94a77362b2'
driver = webdriver.Chrome()
driver.get(first_fallen_url)
resp = requests.get(first_fallen_url)
html = resp.content
soup = BeautifulSoup(html, features="lxml")
with open("page_example.html", "w", encoding="utf-8") as file:
file.write(str(soup))
但是生成的网站是不同的。
解决方案
尝试这个:
import time
from selenium import webdriver
from bs4 import BeautifulSoup
first_fallen_url = r'https://www.izkor.gov.il/%D7%90%D7%94%D7%A8%D7%95%D7%9F%20%D7%94%D7%A8%D7%A9%D7%9C%D7%A8/en_399451c07d6af2edbb259e94a77362b2'
driver = webdriver.Chrome()
driver.get(first_fallen_url)
time.sleep(3)
soup = BeautifulSoup(driver.page_source, features="lxml")
with open("page_example.html", "w", encoding="utf-8") as file:
file.write(str(soup))
driver.close()
推荐阅读
- c# - 部署时Winform应用程序重新启动不起作用
- reactjs - 如何将 ant.design 跨度重置为默认值?
- javascript - 使用 p5.js 在 JavaScript 中未定义 JSON 属性
- java - 将 JButton 添加到 JPanel 到 JFrame
- c# - 在 DbUpdateConcurrencyExpcetion 上实现乐观并发
- python - 如何正确处理类的属性变化?
- git - CVS2GIT-转换:运行 git fast-import 时出现错误“标记...未声明”
- html - css3过渡变换让元素之间的空白
- python - Tensorflow 分桶:用序列填充
- android - Delphi - 小米 Pocophone F1 上的 Android 开发