gpt4 book ai didi

python - 如何抓取与特定期刊/文章论文的每位教授相关的从属关系

转载 作者:行者123 更新时间:2023-12-01 00:22:27 25 4
gpt4 key购买 nike

我要抓取的网站是ScienceDirect 。单击显示更多按钮后,该隶属关系将可用。我可以单击它,但无法抓取单击“显示更多”按钮后加载的从属关系 这是代码。 for 循环不打印包含从属关系的 dl-tag

import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Firefox()

driver.get('https://www.sciencedirect.com/science/article/pii/S1571065308000656')
soup = BeautifulSoup(driver.page_source,'html.parser')
time.sleep(7)

try:
element = driver.find_element_by_css_selector('.show-hide-details.u-font-sans')
element.click()
time.sleep(15)

for data in soup.find(id='author-group'):
print(data)
print('---')

except NoSuchElementException:
pass

最佳答案

我认为您需要将 soup 实例化移至单击“显示更多”按钮之后

如果我运行以下代码:

driver = webdriver.Firefox()

driver.get('https://www.sciencedirect.com/science/article/pii/S1571065308000656')
time.sleep(3)

try:
element = driver.find_element_by_css_selector('.show-hide-details.u-font-sans')
element.click()
time.sleep(9)
soup = BeautifulSoup(driver.page_source,'html.parser')

for data in soup.find(id='author-group'):
print(data)
print('---')

except NoSuchElementException:
pass

我的输出是:

<span class="sr-only">Author links open overlay panel</span>
---
<a class="author size-m workspace-trigger" href="#!" name="baep-author-id6"><span class="content"><span class="text given-name">Ignaz</span><span class="text surname">Rutter</span><span class="author-ref" id="bfn001"><sup>1</sup></span><svg class="icon icon-envelope" focusable="false" height="24" viewbox="0 0 102 128" width="19.125"><path d="m55.8 57.2c-1.78 1.31-5.14 1.31-6.9 0l-31.32-23.2h69.54l-31.32 23.19zm-55.8-24.78l42.94 32.62c2.64 1.95 6.02 2.93 9.4 2.93s6.78-0.98 9.42-2.93l40.24-30.7v-10.34h-102zm92 56.48l-18.06-22.74-8.04 5.95 17.38 21.89h-64.54l18.38-23.12-8.04-5.96-19.08 24.02v-37.58l-1e1 -8.46v61.1h102v-59.18l-1e1 8.46v35.62"></path></svg></span></a>
---
<dl class="affiliation"><dd>Fakultät für Informatik, Universität Karlsruhe, Germany</dd></dl>
---

关于python - 如何抓取与特定期刊/文章论文的每位教授相关的从属关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58861833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com