lancet(go语言工具函数库)发布v2.0.0, 全面支持go泛型特性
这里是一段Python代码,可以用来完成上述任务:import requests
from bs4 import BeautifulSoup
import pandas as pd# 获取期刊最新一期的网页
url = 'https://www.sciencedirect.com/journal/the-lancet'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')# 抓取文章标题、摘要、作者、时间、DOI
titles = []
abstracts = []
authors = []
dates = []
dois = []for tag in soup.find_all('div', class_='art_title'):
title = tag.find('a').text
titles.append(title)
doi = tag.find('a')['href'].split('/')[-1]
dois.append(doi)for tag in soup.find_all('div', class_='auth_list'):
author = tag.text
authors.append(author)for tag in soup.find_all('div', class_='abstract_text'):
abstract = tag.text
abstracts.append(abstract)for tag in soup.find_all('div', class_='art_meta'):
date = tag.find('span', class_='publication_date').text
dates.append(date)# 将爬取的结果存入excel表格
df = pd.DataFrame({'标题': titles, '摘要': abstracts, '作者': authors, '日期': dates, 'DOI': dois})
df.to_excel('the-lancet.xlsx', index=False)