1. 程式人生 > >BS4 select 方法取值

BS4 select 方法取值

# -*- 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)