本文介绍了动态生成表格时,如何使用Python BeautifulSoup来获取表格信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在不使用yahoo或nasdaq的情况下获取收入日历信息,因为它们并不总是准确的.

I am trying to get earnings calendar information without using yahoo or nasdaq since they are not always accurate.

Bloomberg的网站上的收入信息位于以下网址: https://www.bloomberg.com/markets/earnings-calendar/us

Bloomberg's website has earnings information at the following url:https://www.bloomberg.com/markets/earnings-calendar/us

当我检查该页面的html源代码时,我发现了控制日期选择日历工具的html代码块,并检查了一些我已将EV#1,EV#2,EV#3标记为事件代码的事件代码,以及EV#4供参考.

When I inspect the html source for the page, I found the html code block that controls the date picking calendar tool and inspected the some of the event code that I've marked EV#1, EV#2, EV#3, and EV#4 for reference.

<div data-view-uid="1|0_5_9_1"> <----EV#1
    <div class="date-picker">  <--EV#2
        <input id="datepicker" value="04/10/2018" class="hasDatepicker" type="text"> <--EV#3
        <button type="button" class="ui-datepicker-trigger">button</button> <----EV#4
    </div>
</div>

我发现这些EV#n事件中的每一个都引用一些处理点击事件的jQuery代码.

I've found that each of these EV#n events refer to some jQuery code that handle click events.

当我在每个EV#n的Web检查器中突出显示与事件相关的工具箱时,我会看到带有jQuery或冒泡DOM2的代码描述.

When I highlight the event related toolbox in the web inspector at each EV#n, I see code descriptions with either JQuery or Bubbling, DOM2.

我不知道这些是什么意思,但在现阶段也许并不那么重要.我已经包含了说明,以及与以下代码相对应的EV#.也许有帮助..

I have no idea what these mean, but perhaps it's not so important at this stage. I've included the descriptions and which EV#'s correspond to the code below. Perhaps it is helpful..

JQuery:(EV#1)

tellMeTheSelectedDate: function() {
r.locale(this.locale);
var e = this.$datePicker().datepicker("getDate"),
t = r(e).format("L");
a.log(t)
} 

冒泡的DOM2:(EV#1,EV#2,EV#3,EV#4)

function An(e) {
  if (Gi) {
    var t = Cn(e);
    if (t && this.id == t.id) {
      var n = In(t);
      if (n && kn(e)) {
        var r = Rn(n);
        r.PX263 = d(t), re("PX217", r), ji++, Fi <= ji && (Gi = !1, Dn(!1))
      }
    }
  }
}

冒泡的DOM2:(EV#1,EV#4)

u = b.handle = function(e) {
return typeof d === R || e && d.event.triggered === e.type ? void 
0 : d.event.dispatch.apply(u.elem, arguments)
}

jQuery:(EV#4)

function() {
return e.datepicker._datepickerShowing && 
e.datepicker._lastInput === t[0] ? e.datepicker._hideDatepicker() 
: e.datepicker._datepickerShowing && e.datepicker._lastInput !== 
t[0] ? (e.datepicker._hideDatepicker(), 
e.datepicker._showDatepicker(t[0])) : 
e.datepicker._showDatepicker(t[0]), !1
}

目标:

我没有使用JQuery的经验,但是我知道它使用CSS描述符来动态更改Web内容.

I have no experience with JQuery, but I know it uses CSS descriptors to dynamically alter web content.

我是否可以使用Requests并通过修改存储在日历工具中的该值的任何变量来将选择的日期"(日期字符串)发送到日期选择小部件,以便页面刷新(对吗?)并根据我通过脚本传递的日期在表格中显示收入信息?

Is it possible for me to use Requests and send a "picked date" (a date string) to the date picking widget by modifying whatever variable stores this value from the calendar tool so that the page refreshes(is this right?) and displays earnings information in the table based on the date I have passed via script?

我需要模拟一个"click"事件来使页面更新为我的日期吗?

Would I need to emulate a "click" event to get the page to update with my date?

使用bs4从表中获取数据没问题,但是我的主要问题是日期选择.

Getting the data from the table using bs4 is no issue, but my main problem is the date selection.

预先感谢

推荐答案

如果在浏览器(F12)中打开开发人员工具并转到网络"标签,则可以在更改日期时嗅探页面的请求在日历上.这样,您可以将任意日期作为URL参数传递:

If you open developer tools in your browser (F12) and go to the network tab, you can sniff out the request the page is making when you change the date on the calendar. In doing so, you can pass in whichever date you like as a URL parameter:

https://www.bloomberg.com/markets/api/calendar/earnings/US?locale=en&date=2018-04-30

这篇关于动态生成表格时,如何使用Python BeautifulSoup来获取表格信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 21:16