Okay, so let's do a little exploring and think about the
mechanics of this problem. The first thing I'd like to know, is
how do I go about requesting the data I want from this
website? Again, I'm thinking about how I get to a point where
I can actually do this programmatically. So most web browsers give
you the ability to actually inspect individual elements of a webpage, so
in this case, let's just take a look at that selector. And
if we do that, we can see all of the options right
here in the HTML for the page. And based on
our understanding of HTML, we know that it's these values here
that we would need to submit as part of our post
request. Alright, the options for airports look very similar. So instead
of looking at that, let's take a look at The data
that's here. Now, a couple things that I want to point out
here, before we actually look at the HTML again. One is
that for any given airport, this is reporting both domestic and
international flights for that airport. Now in my case, I'm not actually
interested in that distinction. I simply want to know arrivals and departures.
So where does value in both columns, for a given month? I'm
simply going to add them together. So this is one place that
I'm doing a little bit of reshaping of the data. It's also
the case that I've got these totals here in this columns, and
then at the end of the rows for any given year. I'm
simply going to ignore those. Again, a little bit of reshaping. Okay.
So let's take a look at these elements. Now as you
might expect, these are laid out in a table, and if
I scroll to the top, I can actually see there's a
class attribute for this particular table here. And this is going to help
me when it comes time to actually parse this HTML in
order to extract the data. So we've looked at, both how to
go about getting the values we're going to need to submit
in a post request in order to get the data we need.
And then we've looked at once that data is presented to us, or
in this case, to our program that's going to be accessing the site.
How do we go about finding that data and pulling that data out
of the HTML? Or at least where is it located in the HTML file?
حسنًا، فلنستكشف قليلاً آليات
حل هذه المشكلة. أول شيء أريد معرفته يتمثل في
كيف أتعامل مع طلب البيانات التي أريد استخراجها من
موقع الويب هذا؟ وأكرر أنني منشغل بكيفية الوصول إلى الهدف
المتعلق بإمكانية تنفيذ ذلك برمجيًا. حيث توفر لك معظم مستعرضات الويب
،القدرة على فحص عناصر فردية موجودة في صفحة ويب
فدعونا نلقِ نظرة في هذه الحالة الماثلة على المحدد. وإذا
أجرينا ذلك، فيمكننا الاطلاع على جميع الخيارات الموجودة
هنا بتنسيق HTML للصفحة. وبناءً على
فهمنا لطبيعة HTML، نعلم أن هذه القيم
سيلزمنا إرسالها كجزء من
طلب post. حسنًا، إن خيارات المطارات تبدو متشابهة تمامًا. فبدلاً
من الاطلاع على ذلك الشأن، دعونا نلقِ نظرة على البيانات
المعروضة هنا. يوجد الآن شيئان أريد الإشارة إليهما
هنا، وذلك قبل أن نلقي نظرة على تنسيق HTML مرة أخرى. أحدهما يتمثل في
أن هذا الإجراء يعرض الرحلات المحلية والدولية
الخاصة بذلك المطار. ولا أهتم الآن في هذه الحالة الماثلة
.بذلك الفرق. فكل ما أريد معرفته هو مواعيد الوصول والمغادرة
إذًا، فأين تتم إضافة القيمة المتعلقة بشهر معين في كلا العمودين؟ سأعمد ببساطة إلى
إضافتهما معًا. فهذا المكان الذي
،سأعيد فيه تشكيل البيانات. وفي هذه الحالة أيضًا
،وضعت هذه الإجماليات هنا في هذا العمود
ثم في نهاية الصفوف لأي سنة معنية. وسأعمد ببساطة إلى
.تجاهل تلك العناصر. مجددًا، نعمد إلى إعادة التشكيل قليلاً. Okay
،فلنلقِ نظرة على هذه العناصر. وعلى النحو الذي قد تتوقعه
يتم توزيع هذه العناصر في جدول، ويمكنني إذا مرّرت
لأعلى ملاحظة وجود
سمة فئة لهذا الجدول الموجود هنا تحديدًا. إذ سيساعدني ذلك
عندما يحين تحليل تنسيق HTML هذا
لاستخراج البيانات. إذًا، فقد ألقينا نظرة على كيفية
الحصول على القيم التي سيلزمنا إرسالها
.في طلب post للحصول على البيانات اللازمة
ثم ألقينا نظرة أيضًا على البيانات الممثلة لنا أو
.للبرنامج الذي سيصل إلى الموقع في هذه الحالة الماثلة
كيف نضطلع بالبحث عن تلك البيانات واستخراجها
من تنسيق HTML؟ أو على أقل تقدير، أين يوجد موقعها في ملف HTML؟
OK. Vamos explorar um pouco mais e pensar na
mecânica deste problema. A primeira coisa que quero saber é:
como faço para solicitar os dados que eu quero deste
site? Novamente, estou pensando em como chegar a um ponto onde
posso fazer isso programaticamente. Bom, a maioria dos navegadores da Web
permitem de fato inspecionar elementos individuais de uma página da Web, então,
neste caso, vamos ver apenas esse seletor. E
se fizermos isso, poderemos ver todas as opções
aqui no HTML da página. E, com base em
nosso conhecimento de HTML, sabemos que são estes valores aqui
que precisamos enviar como parte de nossa
requisição POST. Certo. As opções dos aeroportos são bem parecidas. Então, em vez
de olhar isso, vamos dar uma olhada nos dados
que estão aqui. Agora, algumas coisas que quero destacar
aqui, antes de analisarmos novamente o HTML de fato. Uma é
que, para determinado aeroporto, ele está relatando voos
domésticos e internacionais. Agora, no meu caso, não estou
interessado nessa distinção. Quero saber simplesmente as chegadas e partidas.
Então, onde houver valor nas duas colunas para determinado mês, vou
simplesmente somá-los. Este é o único lugar em que
vou reformular um pouco os dados. Também
há o caso de que eu tenho estes totais aqui nestas colunas e
depois no final das linhas de determinado ano. Vou
simplesmente ignorá-los. Novamente, um pouco de reformulação. Certo.
Vamos dar uma olhada nestes elementos. Agora, como
já é de se esperar, estes estão organizados em uma tabela e, se
eu rolar para cima, posso ver que há um
atributo de classe para esta tabela aqui. E isso vai me ajudar
quando chegar o momento de analisar este HTML
para extrair os dados. Então, vimos como
obter os valores que vamos precisar enviar
uma requisição POST para obter os dados de que precisamos.
Depois, vimos de uma vez os dados que são apresentados para nós ou,
neste caso, para nosso programa que acessará o site.
Agora, como fazemos para encontrar esses dados e extraí-los
do HTML? Ou pelo menos saber onde eles estão no arquivo HTML?
好 我们来稍作探讨 并思考下
这个问题的技巧 我想指导的第一件事是
我该如何着手从该网站上请求我想要的数据呢?
这一次 我还是要思考如何找到一个突破口
来以编程的方式来解决这个问题 大多数网页浏览器
都能让你检查网页的单个元素
就这种情况而言 我们只需看看该选择符
这样我们可以在这里看到该页的
HTML 中的所有选项
根据我们对于 HTML 的了解 我们知道 这些值
是我们需要作为发帖请求的一部分来提交的
好 机场的选项看起来非常眼熟
我们不看这个 而是要看看这里的数据
这里 在我们再次查看该 HTML 前
我想要指出几点
一个是 对于给定的任何机场 这里给出了
该机场的国内和国际航班 就我个人而言
我对这个差异倒不是很感兴趣 我只是想知道到达与出发的情况
那么对于任何一个月 两列中的值是怎样的呢?
我要把它们加到一起 在这个地方
我要把这个数据稍稍改变一下
基本上是 在这一列得到这些总和
然后在任一指定年的行末 我要
忽略它们 然后 再进行一些改变 好
我们来看看这些元素
正如你可能会预计到的 我把这些列在了一张表里
如果我滚动到顶部 实际上可以看到
该表有一个类属性 这可以
在实际解析该 HTML 以便提取数据时
为我提供帮助 我们已经研究了
如何着手获得需要提交到发帖请求中的值
以便获得所需的数据
还研究了当数据提供给我们后
或者就本例而言 提供给我们即将用来评估网站的程序时
我们该如何着手找到数据
并将其从 HTML 提取出来?或者至少找到其在 HTML 文件中的位置?