BS4 select 方法取值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37195257/article/details/85013880
# -*- coding: utf-8 -*-
import requests

from bs4 import BeautifulSoup

html=requests.get('http://vip.stock.finance.sina.com.cn/corp/view/vCB_BulletinGather.php?page='+str(1))
html.encoding='gbk'
print (html.text)


Soup = BeautifulSoup(html.text, "lxml")
print (Soup)
print ('############')
print (Soup.select('tr a')[0])                 #取第一条a
print (Soup.select('tr a')[0].attrs)              #取a中的标签
print (Soup.select('tr a')[0].string)        #取a中的值(string)

猜你喜欢

转载自blog.csdn.net/qq_37195257/article/details/85013880