<p>
import requests from bs4 import BeautifulSoup response = requests.get(my_url) soup = BeautifulSoup(response.text) soup.find(id="intro-text") # Output: <p>
from selenium import webdriver driver = webdriver.PhantomJS() driver.get(my_url) p_element = driver.find_element_by_id(id_='intro-text') print(p_element.text) # Output: Yay! Supports javascript
import dryscrape from bs4 import BeautifulSoup session = dryscrape.Session() session.visit(my_url) response = session.body() soup = BeautifulSoup(response) soup.find(id="intro-text") # Output: <p>
以上是如何使用 Python 抓取 JavaScript 生成的动态 Web 内容?的详细内容。更多信息请关注PHP中文网其他相关文章!