强大的查询Excel循环日期

如何解决强大的查询Excel循环日期

我想直接在excel powerquery中循环此查询。我想循环链接中找到的日期:从链接中的日期到今天的日期。数据必须全部插入查询中。我该如何解决?谢谢。

let
    Origine = Web.Page(Web.Contents("https://www.forebet.com/scripts/getrs.php?ln=it&tp=bts&in=2019-06-01&ord=0")),Data0 = Origine{0}[Data],Children = Data0{0}[Children],Children1 = Children{1}[Children],#"Rimosse colonne" = Table.RemoveColumns(Children1,{"Kind","Name","Children"}),#"Analizzato JSON" = Table.TransformColumns(#"Rimosse colonne",{},Json.Document),Text = #"Analizzato JSON"{0}[Text],#"Conversione in tabella" = Table.FromList(Text,Splitter.SplitByNothing(),null,ExtraValues.Error),#"Tabella Column1 espansa" = Table.ExpandRecordColumn(#"Conversione in tabella","Column1",{"id","host_id","guest_id","league_id","Round","Host_SC","Guest_SC","DATE","DATE_BAH","Host_SC_HT","Guest_SC_HT","comment","match_preview","host_stadium","match_stadium","HOST_NAME","GUEST_NAME","penalty_score","extra_time_score","goalsavg","host_sc_pr","guest_sc_pr","weather_low","weather_high","weather_code","short_tag","Pred_gg","Pred_no_gg","odds_gg","odds_gg_frac","odds_gg_y","odds_gg_n","odds_gg_y_frac","odds_gg_n_frac"},{"Column1.id","Column1.host_id","Column1.guest_id","Column1.league_id","Column1.Round","Column1.Host_SC","Column1.Guest_SC","Column1.DATE","Column1.DATE_BAH","Column1.Host_SC_HT","Column1.Guest_SC_HT","Column1.comment","Column1.match_preview","Column1.host_stadium","Column1.match_stadium","Column1.HOST_NAME","Column1.GUEST_NAME","Column1.penalty_score","Column1.extra_time_score","Column1.goalsavg","Column1.host_sc_pr","Column1.guest_sc_pr","Column1.weather_low","Column1.weather_high","Column1.weather_code","Column1.short_tag","Column1.Pred_gg","Column1.Pred_no_gg","Column1.odds_gg","Column1.odds_gg_frac","Column1.odds_gg_y","Column1.odds_gg_n","Column1.odds_gg_y_frac","Column1.odds_gg_n_frac"}),#"Riordinate colonne" = Table.ReorderColumns(#"Tabella Column1 espansa",{"Column1.Round","Column1.id",#"Rimosse colonne1" = Table.RemoveColumns(#"Riordinate colonne","Column1.league_id"}),#"Merge di colonne" = Table.CombineColumns(#"Rimosse colonne1",{"Column1.Host_SC","Column1.Guest_SC"},Combiner.CombineTextByDelimiter(":",QuoteStyle.None),"Sottoposto a merge"),#"Merge di colonne1" = Table.CombineColumns(#"Merge di colonne",{"Column1.Host_SC_HT","Column1.Guest_SC_HT"},"Sottoposto a merge.1"),#"Riordinate colonne1" = Table.ReorderColumns(#"Merge di colonne1","Sottoposto a merge","Sottoposto a merge.1",#"Rimosse colonne2" = Table.RemoveColumns(#"Riordinate colonne1",{"Column1.DATE"}),#"Riordinate colonne2" = Table.ReorderColumns(#"Rimosse colonne2",#"Rimosse colonne3" = Table.RemoveColumns(#"Riordinate colonne2",{"Column1.match_preview","Column1.match_stadium"}),#"Riordinate colonne3" = Table.ReorderColumns(#"Rimosse colonne3",#"Rimosse colonne4" = Table.RemoveColumns(#"Riordinate colonne3",{"Column1.penalty_score","Column1.extra_time_score"}),#"Riordinate colonne4" = Table.ReorderColumns(#"Rimosse colonne4",#"Suddividi colonna in base al delimitatore" = Table.SplitColumn(#"Riordinate colonne4",Splitter.SplitTextByDelimiter(" ",QuoteStyle.Csv),{"Column1.DATE_BAH.1","Column1.DATE_BAH.2"}),#"Modificato tipo" = Table.TransformColumnTypes(#"Suddividi colonna in base al delimitatore",{{"Column1.DATE_BAH.1",type date},{"Column1.DATE_BAH.2",type time}}),#"Riordinate colonne5" = Table.ReorderColumns(#"Modificato tipo","Column1.DATE_BAH.1","Column1.DATE_BAH.2",#"Rimosse colonne5" = Table.RemoveColumns(#"Riordinate colonne5",{"Column1.host_sc_pr","Column1.guest_sc_pr"}),#"Riordinate colonne6" = Table.ReorderColumns(#"Rimosse colonne5",#"Rimosse colonne6" = Table.RemoveColumns(#"Riordinate colonne6",{"Column1.odds_gg",#"Modificato tipo1" = Table.TransformColumnTypes(#"Rimosse colonne6",{{"Column1.weather_low",Int64.Type},{"Column1.weather_high",{"Column1.weather_code",Int64.Type}}),#"Sostituito valore" = Table.ReplaceValue(#"Modificato tipo1",".",",Replacer.ReplaceText,{"Column1.odds_gg_y","Column1.goalsavg"}),#"Modificato tipo2" = Table.TransformColumnTypes(#"Sostituito valore",{{"Column1.odds_gg_y",type number},{"Column1.odds_gg_n",{"Column1.goalsavg",{"Column1.Pred_gg",Percentage.Type},{"Column1.Pred_no_gg",Percentage.Type}}),#"Divisa colonna" = Table.TransformColumns(#"Modificato tipo2",{{"Column1.Pred_gg",each _ / 100,#"Divisa colonna1" = Table.TransformColumns(#"Divisa colonna",{{"Column1.Pred_no_gg",Percentage.Type}})
in
    #"Divisa colonna1" 

解决方法

下面的代码应该可以让您获取给定日期范围内的数据。

let
    // Should return JSON for a given date.
    getJsonForDate = (someDate as date) as text => 
        let
            httpResponse = Web.Contents(
                "https://www.forebet.com/scripts/getrs.php",[Query = [ln = "it",tp = "bts",in = Date.ToText(someDate,"YYYY-MM-DD"),order = "0"]]
            ),htmlParsed = Web.Page(httpResponse),extracted = htmlParsed{0}[Data]{0}[Children]{1}[Children]{0}[Text] // Will throw an error if path changes
        in extracted,// Should return JSON for a given date range.
    getJsonForDateRange = (inclusiveStart as date,inclusiveEnd as date) as table =>
        let
            dates = List.Dates(inclusiveStart,Duration.TotalDays(inclusiveEnd - inclusiveStart) + 1,#duration(1,0)),jsonForDates = List.Transform(dates,each [date = _,json = getJsonForDate(_)]),toTable = Table.FromRecords(jsonForDates,type table [date = date,json = text])
        in toTable,// Should return a table representing the JSON passed in.
    parseJsonResponse = (someJson as text) as table => 
        let
            parsed = Json.Document(someJson),toTable = if parsed <> null then Table.FromRecords(parsed) else #table({},{})
        in toTable,data = getJsonForDateRange(#date(2020,8,30),DateTime.Date(DateTime.LocalNow())),parsed = Table.TransformColumns(data,{"json",parseJsonResponse,type table}),expanded = Table.ExpandTableColumn(parsed,"json",{"Round","Host_SC","Guest_SC","DATE_BAH","Host_SC_HT","Guest_SC_HT","comment","HOST_NAME","GUEST_NAME","goalsavg","weather_low","weather_high","weather_code","short_tag","Pred_gg","Pred_no_gg","odds_gg_frac","odds_gg_y","odds_gg_n"}),combineColumns = Table.CombineColumns(expanded,{"Host_SC","Guest_SC"},Combiner.CombineTextByDelimiter(":",QuoteStyle.None),"Sottoposto a merge"),combineColumnsAgain = Table.CombineColumns(combineColumns,{"Host_SC_HT","Guest_SC_HT"},"Sottoposto a merge.1"),transformColumns = Table.TransformColumns(combineColumnsAgain,{
        {"DATE_BAH",each Date.FromText(Text.BeforeDelimiter(_," ")),type date},{"weather_low",Number.From,Int64.Type},{"weather_high",{"weather_code",{"odds_gg_y",each Number.FromText(_,"en-US"),type number},{"odds_gg_n",{"goalsavg",{"Pred_gg",each Number.From(_,"en-US") / 100,Percentage.Type},{"Pred_no_gg",Percentage.Type}
    })
in
    transformColumns

您可以通过将代码中的此行更改为所需的日期范围来更改日期范围。

data = getJsonForDateRange(#date(2020,

  • 最好首先检查网站(www.forebet.com)是否在其服务/使用条款上禁止抓取/漫游器。
  • 当前,每个请求之间没有延迟。因此,如果您指定较大的日期范围,则可能会在很短的时间内发送大量请求,这可能会对他们的服务器产生不利影响。
  • 根据您的问题,代码假定服务器的响应始终是具有特定结构的HTML文档。如果服务器(无论出于何种原因)返回的响应具有不同的结构,则此代码将引发错误。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-