美文网首页
python3 BeautifulSoup爬去股票信息

python3 BeautifulSoup爬去股票信息

作者: 我心有猛虎2018 | 来源:发表于2019-01-20 22:14 被阅读0次

    爬网页信息用到了BeautifulSoup这个,通过这个库能很好的解析网页信息,可以从标签 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)
    
    BaiduShurufa_2019-1-20_22-16-4.png

    相关文章

      网友评论

          本文标题:python3 BeautifulSoup爬去股票信息

          本文链接:https://www.haomeiwen.com/subject/bzbfjqtx.html