teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

文章の修正

2021/03/18 11:51

投稿

Y_ito
Y_ito

スコア3

title CHANGED
File without changes
body CHANGED
@@ -1,23 +1,38 @@
1
1
  ### 前提・実現したいこと
2
- VisualStudioCodeでpythonのスクレイピングのコードを書いていています。不動産サイト、スーモのurlのhttps://suumo.jp/chintai/tokyo/sc_shinjuku/からrequestsモジュールとBeautifulSoupを用いてHTMLのコードを読み込み物件名、住所、アクセス方法、築年数を持ってきたいのですが以下のようなエラが出てしいます
2
+ VisualStudioCodeでpythonのスクレイピングのコードを書いていています。不動産サイト、スーモのurlのhttps://suumo.jp/chintai/tokyo/sc_shinjuku/からrequestsモジュールとBeautifulSoupを用いてHTMLのコードを読み込み物件名、住所、アクセス方法、築年数を持ってきたいので以下のようなドを書きした
3
3
 
4
- ### 発生している問題・エラメッセ
4
+ ### スコ
5
5
 
6
- ```title = detail.find('div', class_='cassetteitem_content-title').text
7
- TypeError: find() takes no keyword arguments
8
- エラーメッセージ
9
- ```
6
+ ```python
7
+ from bs4 import BeautifulSoup
8
+ import requests
10
9
 
10
+ url = 'https://suumo.jp/chintai/tokyo/sc_shinjuku/?page={}'
11
- ### 該当のソースコード
11
+ target_url = url.format(1)
12
+ r = requests.get(target_url)
13
+ soup = BeautifulSoup(r.text)
12
14
 
15
+ contents = soup.find_all('div', class_='cassetteitem')
13
- ```ここに言語名を入力
16
+ content = contents[0]
17
+
14
- ソースコード
18
+ detail = content.find('div', class_='cassetteitem-detail').text
19
+ table = content.find('table', class_='cassetteitem_other').text
20
+
21
+ title = detail.find('div', class_='cassetteitem_content-title').text
22
+ address = detail.find('li', class_='cassetteitem_detail-col1').text
23
+ access = detail.find('li', class_='cassetteitem_detail-col2').text
24
+ age = detail.find('li', class_='cassetteitem_detail-col3').text
15
25
  ```
26
+ ですが、以下のようなエラーが出てしまいました。
27
+ ### エラーメッセージ
28
+ ```
29
+ title = detail.find('div', class_='cassetteitem_content-title').text
30
+ TypeError: find() takes no keyword arguments
16
31
 
17
- ### 試したこと
32
+ ```
18
33
 
19
- ここに問題に対して試したことを記載してください。
20
34
 
21
35
  ### 補足情報(FW/ツールのバージョンなど)
22
36
 
23
- ここにより詳細な情報を記載してください。
37
+ python 3.8.5 64-bit
38
+ VisualStudioCode使用