So, let's talk a little bit about our procedure here. The first thing
we want to do is build a list of all carrier values. We could do
that by hand, might actually be a little easier to do it that way
just by looking at the HTML. We then need to build a list of
airport values. Now there are a lot of values here. So what we
probably want to do is actually write a
little script that will actually pull those
out. Okay. So all pages are going to have exactly the same list for
both of these. So we can just use the browser to download an example
page and pull those values out. Next, what we need to do
is make HTTP requests to download all the data. I'll talk about
why we want to download it all in just a minute. Then what
we want to to is parse the data files. The reason why we
want to do it this way, is because, in building our parser we
want to make sure we're working with data that isn't going to change.
And after the fact, once we do a little bit of data
cleaning, we may discover that the reason why we've got some dirty
data is actually because we have a bug in our parser. Much easier
to figure out where that bug is if we've still got the original data
we were using to parse. I should also point out that it really
doesn't make sense to download the data over and over again as we're figuring
out how to parse it. Something else you might want to keep in
mind is that for years prior to the current year the data isn't going
to change, so there's no reason to retrieve it more than once. So this
is actually a bit of a best practice. When you've got a situation like
the one we have here and when you've got a scraping
task it's often going to look something like this. You really want
to grab all the data you need first and then do your
scraping into separate process. So what we have for this particular problem
is essentially three different steps. We first have to build all the
values we're going to use to make HTTP request. We then need
to make all the HTTP request, and download the data we need.
And then finally, we're going to parse the data we want out
of those data files, shaping it into the particular pieces
of data, the particular items that we want to use.
لنتحدث قليلاً عن الإجراء الموضح هنا. أول شيء
نريد تنفيذه هو إنشاء قائمة بجميع قيم شركات الطيران. ويمكننا إجراء ذلك
يدويًا، إلا أنه قد يكون من الأسهل إجراء ذلك بتلك الطريقة
فقط من خلال إلقاء نظرة على مستند HTML. سنحتاج بعد ذلك إلى إنشاء قائمة
بقيم المطارات. توجد الآن الكثير من القيم هنا. ومن المرجح أننا
نريد كتابة
برنامج نصي صغير الحجم سيؤدي إلى استخراج
تلك القيم. Okay. إذًا، ستشتمل كل الصفحات على القائمة نفسها المماثلة
لهاتين القائمتين. فيمكننا استخدام المستعرض لتنزيل صفحة جاهزة كمثال
واستخراج تلك القيم. بعد ذلك، سنحتاج إلى تقديم
طلبات HTTP لتنزيل جميع البيانات. سأتحدث عن
سبب رغبتنا في تنزيلها لمدة دقيقة واحدة فقط. ثم نريد
تحليل ملفات البيانات. ويكمن السبب الذي يرجع إليه
إجراء ذلك بهذه الطريقة في أننا نريد التأكد أثناء إنشاء
.المحلل من التعامل مع البيانات التي لن تكون عرضة للتغيير
وبعد التحقق، وفور الاضطلاع بقدر قليل من تنظيف
البيانات، قد نكتشف أن السبب في وجود بعض البيانات
المهملة يكمن في وجود خطأ برمجي في المحلل. ومن الأسهل
اكتشاف مكان هذا الخطأ البرمجي إذا كانت البيانات الأصلية
التي كنا نستخدمها للتحليل ما زالت لدينا. ينبغي أيضًا أن أشير إلى عدم جدوى
تنزيل البيانات بشكل متكرر ونحن بصدد
اكتشاف كيفية تحليلها. شيء آخر قد يستدعي وضعه في
الحسبان، وهو أن البيانات لن تكون عرضة للتغيير
قياسًا على السنوات السابقة ووصولاً إلى السنة الحالية، فلا يوجد سبب لاستردادها أكثر من مرة. لذلك، فإن
هذا الإجراء يُعد من أفضل الممارسات. عندما تتعرض لموقف مشابه
للموقف الذي نتعرض له هنا، وعندما توجد مهمة
تعديل، عادةً ما نلجأ إلى شيء كهذا. حيث تريد
الحصول على كل البيانات التي تحتاج إليها أولاً، ثم تعمد إلى
التحول لعملية مستقلة. وتوجد ثلاث خطوات مختلفة
لحل هذه المشكلة تحديدًا. يتعين علينا أولاً إنشاء جميع
القيم التي سنستخدمها لإجراء طلب HTTP. ثم نحتاج إلى إجراء
.طلب HTTP كامل وتنزيل البيانات اللازمة
وأخيرًا، سنعمد إلى تحليل البيانات التي نريدها
من ملفات البيانات تلك، وذلك من خلال تشكيلها إلى أجزاء محددة
.من البيانات، والتي تتمثل في عناصر محددة نريد استخدامها
Vamos falar um pouco sobre procedimento. Primeiro,
vamos criar uma lista de todos os valores carrier. Poderíamos
fazer isso manualmente. Talvez fosse mais fácil fazer isso
verificando apenas o HTML. Depois, precisamos criar uma
lista de valores airport. Há muitos valores aqui. Na verdade,
provavelmente desejamos escrever um
script que extrairá
isso. Certo. Todas as páginas terão exatamente a mesma lista nos
dois casos. Podemos usar o navegador para baixar uma página de
exemplo e extrair esses valores. Em seguida, precisamos
fazer requisições HTTP para baixar todos os dados. Daqui a pouco,
você saberá por que quero baixar tudo isso. Depois,
queremos analisar os arquivos de dados. Queremos fazer
desta forma porque, ao criar o analisador, buscamos garantir
que estamos trabalhando com dados que não vão mudar.
Depois disso, após alguma limpeza de dados,
podemos descobrir que o motivo da presença de dados sujos é,
na verdade, um bug no nosso analisador. É bem mais
fácil descobrir onde está o bug se ainda temos os dados originais
usados na análise. Devo frisar que também não faz
sentido baixar os dados várias vezes pois estamos tentando descobrir como
analisá-los. Lembre-se também de que,
muitos anos antes do ano vigente, os dados não mudariam; então, não há motivo
para recuperá-los mais de uma vez. Esta
é a prática recomendável. Ao se deparar com uma situação
assim, e quando tiver uma tarefa de captura,
ela terá esta aparência. Primeiro, você
quer reunir todos os dados necessários. Depois, fará
a captura em um processo separado. Temos, basicamente, três etapas diferentes
para este problema específico. Primeiro, criamos todos os
valores que usaremos para fazer a requisição HTTP. Depois,
precisamos fazer todas as requisições HTTP e baixar os dados necessários.
Finalmente, analisaremos os dados desses arquivos de
dados, definindo-os como dados específicos,
os itens específicos que queremos usar.
那么我们来谈谈我们的程序 我们首先要做的是
创建一个所有承运人值的列表 这个可以手动完成
可能比研究 HTML 的方法还更简单些
然后我们需要创建一个机场值的列表
现在这里有很多值
我们可能需要做的是编写一个小脚本
该脚本可以把它们提取出来
好的 所有页面都将具有这两者的相同列表
我们可以用浏览器来下载一个示例页面
从中提取这些值 接下来 我们需要
发出 HTTP 请求以下载所有数据 我稍后要谈一下
为什么我们想要立刻下载这些数据
然后我们要解析数据文件 我们想要这样做的原因是
在创建解析器时
我们想要确保使用不会改变的数据
事后 一旦我们进行一些数据清理
就可以发现我们之所以会得到一些废数据
是因为解析器中有一个 bug
如果我们依然拥有用于解析的原始数据 要找出 bug 的位置会容易很多
我还要指出
当我们弄清如何解析的时候 一次次重复下载数据真的毫无意义
你可能需要牢记的是
对于当年之前的年度 数据不会改变
所以没有理由多次去检索
这确实是一种最佳实践 如果你遇到类似这样的情况
且当你有一个抓取任务时
通常都会是类似这样的情况 你真的想要
首先抓取需要的所有数据 然后通过单独的程序
进行抓取 因此 对于这个问题
我们的解决方法基本上分三步 首先需要创建用来发出 HTTP 请求时
将用到的所有值 然后需要
发出所有 HTTP 请求 并下载所需的数据
最后 我们要解析这些数据文件中需要的数据
将其打造为特定的数据块
即我们想要使用的具体项目