在Google Chrome检查元素中,我可以通过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')
答案 0 :(得分:0)
我猜,服务器正在检查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