爬網(wǎng)頁信息用到了BeautifulSoup這個(gè)辐马,通過這個(gè)庫能很好的解析網(wǎng)頁信息岛请,可以從標(biāo)簽 css等方式取信息 .
import requests
from bs4 import BeautifulSoup
headers = {'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
reponse = requests.get('http://quote.stockstar.com/stock/gem.shtml')
reponse.encoding = 'GBK'
soup = BeautifulSoup(reponse.text,'lxml')
trs = soup.select('tbody.tbody_right')[0].select('tr')
for i in trs:
print(i.text)
print('*'*50)
datalist = soup.find_all(id='datalist')
for a in datalist[0].select('tr'):
print(a.text)