30[ガキ手帳]-破片機能の実装を試みる





すべてのプロジェクトを完了する前に、api設計をまず行わなければなりません.
テストするフラグメント機能:
場合によっては、
ページ上のmetaタグの順序がPythonコード接続時のmetaタグの順序と異なるため


美容グループのその他の使い方
コピー

コマンドmetaラベルから次の属性属性属性=og:title一致を取得します.
import requests
from bs4 import BeautifulSoup
url = 'https://movie.naver.com/movie/bi/mi/basic.nhn?code=171539'
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(url,headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
title = soup.select_one('meta[property="og:title"]')
print(title)
実行結果(インポートに成功)C:\Users\rokimo\Desktop\sparta\projects\alonememo\venv\Scripts\python.exe C:/Users/rokimo/Desktop/sparta/projects/alonememo/meta_prac.py
<meta content="그린 북" property="og:title"/>
Process finished with exit code 0
print(title[「content」)を入力すると、テキストのみがインポートされます.
import requests
from bs4 import BeautifulSoup
url = 'https://movie.naver.com/movie/bi/mi/basic.nhn?code=171539'
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(url,headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
title = soup.select_one('meta[property="og:title"]')['content']
print(title)
実行結果C:\Users\rokimo\Desktop\sparta\projects\alonememo\venv\Scripts\python.exe C:/Users/rokimo/Desktop/sparta/projects/alonememo/meta_prac.py
그린 북
Process finished with exit code 0
上記のように複数の要素をスクロールし続けます.
import requests
from bs4 import BeautifulSoup
url = 'https://movie.naver.com/movie/bi/mi/basic.nhn?code=171539'
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(url,headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
title = soup.select_one('meta[property="og:title"]')['content']
image = soup.select_one('meta[property="og:image"]')['content']
desc = soup.select_one('meta[property="og:description"]')['content']
print(title,image,desc)
実行結果C:\Users\rokimo\Desktop\sparta\projects\alonememo\venv\Scripts\python.exe C:/Users/rokimo/Desktop/sparta/projects/alonememo/meta_prac.py
그린 북 https://movie-phinf.pstatic.net/20190115_228/1547528180168jgEP7_JPEG/movie_image.jpg?type=m665_443_2 1962년 미국, 입담과 주먹만 믿고 살아가던 토니 발레롱가(비고 모텐슨)는 교양과 우아함 그 자체인천재...
Process finished with exit code 0
Reference
この問題について(30[ガキ手帳]-破片機能の実装を試みる), 我々は、より多くの情報をここで見つけました https://velog.io/@yh271/webbase30テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol