Beautifulsoup分别用find、find_all和select爬取论文信息

本文介绍了如何利用Beautifulsoup的find、find_all和select方法来抓取网页上的论文信息。find仅获取第一条匹配结果,而find_all和select则能获取所有匹配的内容。示例中,作者展示了这些方法在处理论文链接时的运用。
摘要由CSDN通过智能技术生成

分别用find、find_all和select爬取论文信息

find只会爬取到第一条满足条件的信息,而find_all和select会爬取所有满足条件的信息

论文链接
find和find_all方法:

import requests
from bs4 import BeautifulSoup
from requests import RequestException
def get_html(url):
	try:
		headers = {
			'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36'
		}
		respons = requests.get(url, headers=headers)
		if respons.status_code == 200:
			respons.encoding = respons.apparent_encoding
			return respons.text
		return None
	except RequestException as e:
		print(e)
		return None
		
if __name__ == "__main__":
	url = 'http://www.wanfangdata.com.cn/details/detail.do?_type=perio&id=zgszyx201807023'
	h
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值