首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用Python抓取可点击内容的网站

用Python抓取可点击内容的网站
EN

Stack Overflow用户
提问于 2015-03-11 04:04:34
回答 1查看 615关注 0票数 1

我想取消以下网站的内容:

http://financials.morningstar.com/ratios/r.html?t=AMD

在那里,在键比率下,,我想点击"Growth“按钮,然后销毁中的数据。

我怎么能这么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-11 04:20:23

您可以使用requests+BeautifulSoup来解决它。有一个异步GET请求发送到需要模拟的http://financials.morningstar.com/financials/getKeyStatPart.html端点。Growth表位于带有id="tab-growth"div中。

代码语言:javascript
复制
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.text
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28978362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档