本帖最后由 function2046 于 2016-5-27 22:42 编辑
目标网页:http://quote.stockstar.com/stock/ranklist_a_3_1_1.html(网页结构是 http://quote.stockstar.com/stock/ranklist_a_3_1_第几个页面.html)我们需要获取该网站中的95个页面信息,每一个页面如下:
现在点击:
输入并点击确定:
点击这个:
会出现:
点击“编辑”,后出现这个,选择“高级编辑”:
出现这个:
原本的M语句:
let
源 = Web.Page(Web.Contents("http://quote.stockstar.com/stock/ranklist_a_3_1_1.html")),
Data0 = 源{0}[Data],
更改的类型 = Table.TransformColumnTypes(Data0,{{"代码", type text}, {"简称", type text}, {"最新价", type text}, {"涨跌幅", type text}, {"涨跌额", type text}, {"5分钟涨幅", type text}, {"成交量(手)", type text}, {"成交额(万元)", type text}, {"换手率", type text}, {"振幅", type text}, {"量比", type text}, {"委比", type text}, {"市盈率", type text}, {"Column14", type text}, {"Column15", type text}, {"Column16", type text}})
in
更改的类型
现在需要自定义一个获取网页的函数:
我们需要在原来的M语句上加上(必须是英文输入法下)
(page as number) as table=>
修改后的M:
(page as number) as table=>
let
源 = Web.Page(Web.Contents("http://quote.stockstar.com/stock/ranklist_a_3_1_"& Number.ToText(page) &".html")),
Data0 = 源{0}[Data],
更改的类型 = Table.TransformColumnTypes(Data0,{{"代码", type text}, {"简称", type text}, {"最新价", type text}, {"涨跌幅", type text}, {"涨跌额", type text}, {"5分钟涨幅", type text}, {"成交量(手)", type text}, {"成交额(万元)", type text}, {"换手率", type text}, {"振幅", type text}, {"量比", type text}, {"委比", type text}, {"市盈率", type text}, {"Column14", type text}, {"Column15", type text}, {"Column16", type text}})
in
更改的类型
修改完成后,点击保存
名字改为:getdata
保存:
开一个空的查询表:
点击“高级编辑",输入{1..95}:
将其转为table:
点击“添加列"=>"添加自定义列",输入我们刚才自定义的函数getdata点击确定:
展开:
结果如下:
所有的页面就都全部获取了
也可以在空白的查询中的“高级编辑”中输入如下M语句,获取网页信息:
let
查询1 = {1..95},
转换为表 = Table.FromList(查询1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
已添加自定义 = Table.AddColumn(转换为表, "Custom", each getdata([Column1])),
#"展开的“Custom”" = Table.ExpandTableColumn(已添加自定义, "Custom", {"代码", "简称", "最新价", "涨跌幅", "涨跌额", "5分钟涨幅", "成交量(手)", "成交额(万元)", "换手率", "振幅", "量比", "委比", "市盈率", "Column14", "Column15", "Column16"}, {"Custom.代码", "Custom.简称", "Custom.最新价", "Custom.涨跌幅", "Custom.涨跌额", "Custom.5分钟涨幅", "Custom.成交量(手)", "Custom.成交额(万元)", "Custom.换手率", "Custom.振幅", "Custom.量比", "Custom.委比", "Custom.市盈率", "Custom.Column14", "Custom.Column15", "Custom.Column16"})
in
#"展开的“Custom”"
|