Python解析Evernote共享笔记

2024-10-03 06:23:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从evernote“共享笔记本”获取数据。 例如,从这个开始:https://www.evernote.com/pub/missrspink/evernoteexamples#st=p&n=56b67555-158e-4d10-96e2-3b2c57ee372c

我试着用靓汤:

url = 'https://www.evernote.com/pub/missrspink/evernoteexamples#st=p&n=56b67555-158e-4d10-96e2-3b2c57ee372c'
r = requests.get(url)
bs = BeautifulSoup(r.text, 'html.parser')
bs

结果不包含来自笔记本的任何文本信息,只有一些代码。在

我还看到了使用selenium和通过XPath查找元素的建议。 例如,我想找到这张便条的标题-“第3学期第2周”。在googlechrome中,我发现它的XPath是'/html/body/div[1]/div[1]/b/span/u/b'。 所以我试了一下:

^{pr2}$

但它也没用,结果是“无动于衷”异常:。。。'. 在

我是python的新手,尤其是语法分析,所以我很乐意接受任何帮助。 我使用的是python3.6.2和jupiter笔记本。在

提前谢谢。在


Tags: httpsdivcomurlbshtmlwww笔记本
1条回答
网友
1楼 · 发布于 2024-10-03 06:23:31

与Evernote接口的最简单方法是使用它们的official Python API。在

在配置了API密钥并可以进行连接之后,您就可以下载和参考笔记和笔记本了。在

Evernote注释使用自己的模板语言ENML(Evernote标记语言),它是HTML的一个子集。您将能够使用beauthoulsoup4解析ENML并提取您要查找的元素。在

如果您试图针对本地安装(而不是他们的web应用程序)提取信息,您也可以从可执行文件中获取所需的信息。请参阅本地安装的how to pass arguments以提取数据。为此,您需要使用Python3^{}模块。在

但是

如果您想使用selenium,这将帮助您开始:

import selenium.webdriver.support.ui as ui
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

# your example URL
URL = 'https://www.evernote.com/pub/missrspink/evernoteexamples#st=p&n=56b67555-158e-4d10-96e2-3b2c57ee372c'

# create the browser interface, and a generic "wait" that we can use
#  to intelligently block while the driver looks for elements we expect.
#  10:  maximum wait in seconds
# 0.5:  polling interval in seconds
driver = Chrome()
wait = ui.WebDriverWait(driver, 10, 0.5)

driver.get(URL)

# Note contents are loaded in an iFrame element
find_iframe = By.CSS_SELECTOR, 'iframe.gwt-Frame'
find_html = By.TAG_NAME, 'html'

# .. so we have to wait for the iframe to exist, switch our driver context
#  and then wait for that internal page to load.
wait.until(EC.frame_to_be_available_and_switch_to_it(find_iframe))
wait.until(EC.visibility_of_element_located(find_html))

# since ENML is "just" HTML we can select the top tag and get all the 
#  contents inside it.
doc = driver.find_element_by_tag_name('html')

print(doc.get_attribute('innerHTML'))  # <  this is what you want

# cleanup our browser instance
driver.quit()

相关问题 更多 >