優れたプログラミングコードの例を示して
- User
優れたプログラミングコードの例を示して
Assistant
Pythonでの簡単なウェブスクレイピングコードを以下に示します。この例では、
requestsとBeautifulSoupライブラリを使用し、特定のウェブページからデータを抽出します。import requests from bs4 import BeautifulSoup # ウェブサイトのURL url = 'http://example.com' # リクエストを送る response = requests.get(url) # レスポンスからHTMLデータを取得 html = response.text # BeautifulSoupオブジェクトを作成 soup = BeautifulSoup(html, 'html.parser') # データを抽出するためのタグ名 data_tag = 'h1' # タグを取得し、結果を表示 data = soup.find(data_tag) if data: print(data.text.strip()) else: print('タグが見つかりませんでした。')このコードは、指定されたウェブページの
<h1>タグを見つけ、そのテキストをコンソールに出力します。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.