我希望从网页中提取生成的内容。
我使用python 3中的库请求返回页面,如下所示
import requests
url = "https://app.updateimpact.com/treeof/org.json4s/json4s-
native_2.11/3.5.2"
html_doc = requests.get(url)
print(html_doc.text)检索的文本似乎只是填充。我应该看什么工具来钻研内容和提取那里的信息?
发布于 2019-02-16 18:04:59
Javascript需要在页面上运行以提供大部分内容。使用selenium这样的方法将允许运行这种方法。请注意,需要额外的等待条件来确保加载某些内容。然后,您可以使用selenium语法提取信息或将page_source中的html转储到BeautifulSoup中。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup as bs
d = webdriver.Chrome()
d.get('https://app.updateimpact.com/treeof/org.json4s/json4s-native_2.11/3.5.2')
dependencies = WebDriverWait(d, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR , '.stats-list')))
print(dependencies)
soup = bs(d.page_source, 'lxml')
print(soup.select_one('#tree').text) # example发布于 2019-02-16 16:29:57
https://stackoverflow.com/questions/54725160
复制相似问题