簡體   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