我想取消以下网站的内容:
http://financials.morningstar.com/ratios/r.html?t=AMD
在那里,在键比率下,,我想点击"Growth“按钮,然后销毁中的数据。
我怎么能这么做?
发布于 2015-03-11 04:20:23
您可以使用requests+BeautifulSoup来解决它。有一个异步GET请求发送到需要模拟的http://financials.morningstar.com/financials/getKeyStatPart.html端点。Growth表位于带有id="tab-growth"的div中。
from bs4 import BeautifulSoup
import requests
url = 'http://financials.morningstar.com/ratios/r.html?t=AMD'
keystat_url = 'http://financials.morningstar.com/financials/getKeyStatPart.html'
with requests.Session() as session:
session.headers = {'User-Agent': 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'}
# visit the target url
session.get(url)
params = {
'callback': '',
't': 'XNAS:AMD',
'region': 'usa',
'culture': 'en-US',
'cur': '',
'order': 'asc',
'_': '1426047023943'
}
response = session.get(keystat_url, params=params)
# get the HTML part from the JSON response
soup = BeautifulSoup(response.json()['componentData'])
# grab the data
for row in soup.select('div#tab-growth table tr'):
print row.texthttps://stackoverflow.com/questions/28978362
复制相似问题