質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
スクレイピング

スクレイピングとは、公開されているWebサイトからページ内の情報を抽出する技術です。

Beautiful Soup

Beautiful Soupは、Pythonのライブラリの一つ。スクレイピングに特化しています。HTMLデータの構文の解析を行うために、HTMLタグ/CSSのセレクタで抽出する部分を指定することが可能です。

import

自身のプラットフォーム・プログラム・データセットに対して、外部ソースを取り込むプロセスをimportと呼びます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

598閲覧

抽出したタイトルを一行ごとにしたい

zen913

総合スコア21

スクレイピング

スクレイピングとは、公開されているWebサイトからページ内の情報を抽出する技術です。

Beautiful Soup

Beautiful Soupは、Pythonのライブラリの一つ。スクレイピングに特化しています。HTMLデータの構文の解析を行うために、HTMLタグ/CSSのセレクタで抽出する部分を指定することが可能です。

import

自身のプラットフォーム・プログラム・データセットに対して、外部ソースを取り込むプロセスをimportと呼びます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/10/04 01:11

編集2019/10/04 01:38

抽出したタイトルを一行ごとにして見やすくしたい

python

1import requests, bs4 2 3result = [] 4for num in range(1,4): 5 res = requests.get(f'https://journals.sagepub.com/toc/trjc/88/{num}') 6 res.raise_for_status() 7 soup = bs4.BeautifulSoup(res.text, "html.parser") 8 elems = soup.select('.heading-title') 9 for elem in elems: 10 result.append(elem.text) 11print(result) 12

結果

['Development of disperse dye polypropylene fiber and process parameter optimization Part I: development of dyeable polypropylene fiber and parameter optimization', 'Measurement of short fiber contents in raw cotton using dual-beard images', 'Laccase-mediated in situ polymerization of pyrrole for simultaneous coloration and conduction of wool fabric', 'Sound absorption of textile curtains – theoretical models and validations by experiments and simulations', 'Modeling and analysis of the carrier arrangement in three-dimensional circular braiding', 'Analysis of physical properties and structure design of weft-knitted spacer fabric with high porosity', 'Novel moisture management test of polyethylene terephthalate and nylon fabric under stretching and surface patterning', 'High-throughput nanofiber produced by needleless electrospinning using a metal dish as the spinneret', 'Optimization of durability of Persian hand-knotted wool carpets by using desirability functions', 'Silk fabrics modification by sol–gel method', 'The influence of surface hydrophilicity on the adhesion properties of wet fabrics or films to water', 'The graft polymerization of vinyl benzoate and trans-stilbene onto polyurethane to control its mechanical and shape memory properties', 'Mathematical analysis of motion control in sectional warping machines', 'Electrically conducting linen fabrics for technical applications', 'Effect of treatment temperature on structures and properties of flax rove in supercritical carbon dioxide', 'Automatic foot scanning and measurement based on multiple RGB-depth cameras', 'Hydrophilic and antimicrobial properties of acrylic acid and chitosan bigrafted polypropylene melt-blown nonwoven membrane immobilized with silver nanoparticles', 'Fiber packing density in the cross-section of low torque ring spun yarn', 'Comparison of airf\u2009low environmental effects on thermal fabrics', 'Geometrical design and forming analysis of three-dimensional woven node structures', 'Fictitious forces in yarn during unwinding from packages', 'Numerical simulation of three-dimensional airflow in a novel dual-feed rotor spinning box', 'The structure and properties of wool treated with a reversed-phase microemulsion containing aqueous alkali', 'Creation of electro-conductive paths and patterns by screen printing on textile bases', 'Characterization of functional single jersey knitted fabrics using non-conventional yarns for sportswear', 'Investigation of the thermal properties of spacer fabrics with bio-ceramic additives using the finite element model and experiment', 'Study on the coiler drive mechanism of the capacity increasing function', 'A weaving machine for three-dimensional Kagome reinforcements', 'Experimental investigation of the tensile and bending behavior of multi-axial warp-knitted fabric composites', 'Development and testing of controlled adaptive fiber-reinforced elastomer composites']

上記のようになってしまいます。
どうすればタイトルを一行ごともってくることができるのでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2019/10/04 01:30

抽出したタイトルとはどれのことを言ってるんでしょうか。 現状だとどうなっていてそれをどうしたいんでしょう あまりにも説明不足ですぜ
guest

回答2

0

pprint を使うとか。

https://docs.python.org/ja/3/library/pprint.html

Python

1from pprint import pprint 2pprint(result)

投稿2019/10/04 03:04

magichan

総合スコア15898

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

print(*result, sep='\n') あるいは print('\n'.join(result)) で。
for文を使って書いても良いです。

投稿2019/10/04 01:39

LouiS0616

総合スコア35658

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

zen913

2019/10/04 03:21

ありがとうございます!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問