Web開発総合クラス第3週-Python基礎(1)
4762 ワード
ベスト4-Pythonを開始
パイゴンで新しいプロジェクトを作成します.
Locationを使用してフォルダの場所を確認し、venvフォルダが作成されていることを確認します.
main.py生成チェックを無効にする


この時点で生成されたvenvフォルダは触られません.

Omarclick-Python FileをクリックしてPythonファイルを作成

ファイル名で実行するのに慣れています
5講-Phython基礎学習
すべての文法を暗記できないので、グーグル化の習慣を身につけることが大切です.

必要な値を変数に挿入して印刷すると、その値が表示されます.
JSのコンソール.ロゴとかのようです.

エラーが発生した場合は、エラーメッセージの最後の行をよく確認してください.
このエラーは、宣言されていない変数を使用して発生したエラーです.

数字や文字の追加もエラーの原因の一つです
原因を見つけるのが難しい場合は、最後の行をコピーしてグーグル検索を行うことで、ほとんどの問題を解決することができます.
これらのエラーには、次のものが含まれます.
num = str(2)
文字列2で解決できます


JSに似ている


また、Pythonの関数には括弧がないので、インデントスペースをチェックしなければなりません!インデントされた場所への関数


IF構文


複文


!!いつどこで使うかなど、背負い込む必要はありません.これは制作庫などの人次第なので、ほほほ
6鋼-Pythonパッケージのインストール
第7回-試用パッケージ

要求パケットを使用して、ダストAPIをインポートします.
繰り返し文とif文を使用して、濃度が40を超えるスモッグのみを出力します.
8鋼-Web scraping(ローリング)ベース

ページの受信を要求するパッケージ
bs 4パケット受信ページ情報をフィルタリングする

NAVERムービーページのhtmlタグセレクタのインポート
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get('https://movie.naver.com/movie/sdb/rank/rmovie.nhn?sel=pnt&date=20200303',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
title = soup.select_one('#old_content > table > tbody > tr:nth-child(2) > td.title > div > a')
print(title.xetx)
選択者を肩書きにつける.print(title)の場合、選択したコンテンツのhtmlコードをインポートできます.print(title.text)の場合、選択したコンテンツのテキストをインポートできます.
aラベルのプロパティを取得するには、印刷(title[「href」)

soup.select oneは1つのオブジェクトしかインポートできないので、複数の映画リストをインポートするにはsoupを使用します.selectを使用する必要があります

copy selectorを使用して選択プログラムをチェックします.
別の部分をクリアし、セレクタをオーバーラップ部分として使用

複数のtrを読み込み、for文で回転
for文では、tr.select oneを使用してtrのaタグを検索します.


ただし、trタグにはtext要素を含まないオブジェクトが存在する可能性があります.
これによりエラーが発生します.
for tr in trs:
a_tag = tr.select_one(' td.title > div > a')
if a_tag is not None:
title = a_tag.text
print(title)
if文を使用してコードを記述し、None以外の場合にのみ表示第9講-Quiz Web Screeping(スクロール)練習
for tr in trs:
a_tag = tr.select_one(' td.title > div > a')
if a_tag is not None:
rank = tr.select_one('td:nth-child(1) > img')['alt']
title = a_tag.text
point= tr.select_one(' td.point').text
print(rank,title,point)
繰り返しtrでランキングとスコアを検索し、変数に保存します.出力はprint(rank、title、point)
コードは、データを取得するプロセスによって異なる場合があります.ただ重要なのは短くて効率的なコードをもたらすことです!
Reference
この問題について(Web開発総合クラス第3週-Python基礎(1)), 我々は、より多くの情報をここで見つけました https://velog.io/@specter38/스파르타-웹개발-종합반-3주차-파이썬-기초テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol