我有一个应用程序,使用requests来分析和行动的网页文本。但是在这个可能是用angular:https://bio.tools/bowtie构建的页面上,它似乎不起作用,因为源HTML与实际内容不同。我正在尝试收集页面上引用的DOI (10.1186/gb-200910-3-R25),但是当请求获取HTML源代码时,DOI就不在那里了。
我听说Google能够解析使用javascript生成的页面。他们是怎么做到的?关于使用python查看DOI信息有什么建议吗?
发布于 2020-03-10 08:31:54
您可能需要一个引擎来为您运行http响应的javascript (就像internet浏览器一样)。为此,您可以使用selenium,然后使用beautifulsoup解析它返回的html。
示例:
from selenium import webdriver
from bs4 import BeautifulSoup
url = "https://bio.tools/bowtie"
path = "path/to/chrome/webdriver"
browser = webdriver.Chrome(path) # Can also be Firefox, etc.
browser.get(url)
html = browser.page_source
soup = BeautifulSoup(html, 'html.parser')
...https://stackoverflow.com/questions/60610062
复制相似问题