繁体   English   中英

request.get()Python 2上的数据丢失

[英]Data missing on requests.get() Python 2

我想在https://www.settrade.com/AnalystConsensus/C04_10_stock_saa_p1.jsp?txtSymbol=PTT&ssoPageId=9&selectPage=10上草绘IAA共识价格

在Google chrome inspect元素中,我可以通过beautifulsoup使用<h3>来获取数据。 但是从打印page.content我得到

...
<h3 class="colorGreen"></h3>
...

应该在<h3 class="colorGreen">62.00</h3>

这是我的代码

import requests
from bs4 import BeautifulSoup

def findPrice(Quote):
    link = "http://www.settrade.com/AnalystConsensus/C04_10_stock_saa_p1.jsp?txtSymbol="+Quote+"&ssoPageId=9&selectPage=10"
    page = requests.get(link)
    soup = BeautifulSoup(page.content,'html.parser')

    print page.content
    target = soup.findAll('h3')
    return target.string

findPrice('PTT')

我猜服务器正在检查LstQtLst cookie,并生成带有“共识目标价格”的HTML。

import requests
from bs4 import BeautifulSoup


def find_price(quote):
    link = ('http://www.settrade.com/AnalystConsensus/C04_10_stock_saa_p1.jsp'
            '?txtSymbol={}'
            '&ssoPageId=9'
            '&selectPage=10'.format(quote))

    html = requests.get(link, cookies={'LstQtLst': quote}).text
    soup = BeautifulSoup(html, 'html.parser')

    price = soup.find('h3').string
    return price
>>> find_price('PTT')
62.00

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM