我想用Python和BeautifulSoup从Ullmann's Encyclopedia of Industrial Chemistry中提取所有章节的DOI。
所以来自
<h2 class="meta__title meta__title__margin"><span class="hlFld-Title"><a href="/doi/10.1002/14356007.c01_c01.pub2">Aerogels</a></span></h2>
我想得到#34; Aerogels&#34;和&#34; /doi/full/10.1002/14356007.c01_c01.pub2"
更大的样本:
<ul class="chapter_meta meta__authors rlist--inline comma">
<li><span class="hlFld-ContribAuthor"><a href="/action/doSearch?ContribAuthorStored=H%C3%BCsing%2C+Nicola"><span>Nicola Hüsing</span></a></span></li>
<li><span class="hlFld-ContribAuthor"><a href="/action/doSearch?ContribAuthorStored=Schubert%2C+Ulrich"><span>Ulrich Schubert</span></a></span></li>
</ul><span class="meta__epubDate"><span>First published: </span>15 December 2006</span><div class="content-item-format-links">
<ul class="rlist--inline separator">
<li><a title="Abstract" href="/doi/abs/10.1002/14356007.c01_c01.pub2">Abstract</a></li>
<li><a title="Full text" href="/doi/full/10.1002/14356007.c01_c01.pub2">
Full text
</a></li>
对于我尝试过的标题:
span['hlFld-Title'].a
对于我尝试过的DOI:
for link in soup.find_all('a'.title):
print(link.get('href'))
但遗憾的是,我是一个完整的菜鸟(傻瓜)而且它不起作用。
网址为https://onlinelibrary.wiley.com/browse/book/10.1002/14356007/title?startPage= {1..59}
感谢您的帮助。
答案 0 :(得分:0)
这是一个快速解决方案,将“DOI; title”对打印到命令行:
import requests
from bs4 import BeautifulSoup
for i in range(59):
page = requests.get("https://onlinelibrary.wiley.com/browse/book/10.1002/14356007/title?startPage={}".format(i))
soup = BeautifulSoup(page.content, 'lxml')
content = soup.findAll("span", class_="hlFld-Title")
for c in content:
print(c.a.get('href')+";"+c.get_text())