前提・実現したいこと
- 目的:こちらのWebサイトのhtmlを取得したい。
発生している問題・エラーメッセージ
pythonとbeautifulsoup4,requestsを使用して上記のサイトからurlを取得しようとしたが取得したhtmlが望んでいるものと異なる。
クエリパラメータの内容を受けっとた結果が返ってこず
https://character-sheets.appspot.com/shinobigami/edit.html
のhtmlを取得している。
該当のソースコード
python
1import requests 2from bs4 import BeautifulSoup 3 4url = 'https://character-sheets.appspot.com/shinobigami/edit.html' 5params = {'key' : 'ahVzfmNoYXJhY3Rlci1zaGVldHMtbXByFwsSDUNoYXJhY3RlckRhdGEYhtPUpgEM'} 6 7response = requests.get(url, params=params) 8print(response.url) 9soup = BeautifulSoup(response.content, "html.parser") 10print('title:',soup.title.string) 11print(soup)
結果
cmd
1https://character-sheets.appspot.com/shinobigami/edit.html?key=ahVzfmNoYXJhY3Rlci1zaGVldHMtbXByFwsSDUNoYXJhY3RlckRhdGEYhtPUpgEM 2title: シノビガミ 3<html> 4<head> 5<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> 6<meta content="TRPG,キャラクターシート,シノビガミ" name="keywords"/> 7<meta content="シノビガミのキャラクター。" name="description"/> 8<title>シノビガミ</title> 9<link href="../common/css/global.css" media="all" rel="stylesheet" type="text/css"/> 10<link href="../common/css/dice_fiction.css" media="all" rel="stylesheet" type="text/css"/> 11<link href="../common/css/jquery.miniColors.css" media="all" rel="stylesheet" type="text/css"/> 12<link href="./css/shinobigami.css?20111004" media="all" rel="stylesheet" type="text/css"/> 13<script src="../common/js/json_table.js?20120301" type="text/javascript"></script> 14<script src="../common/js/dice_fiction.js?20110707" type="text/javascript"></script> 15<script src="../common/js/jquery.js" type="text/javascript"></script> 16<script src="../common/js/jquery.csmp.js?20111024" type="text/javascript"></script> 17<script src="../common/js/jquery.upload-1.0.2.min.js?20111004" type="text/javascript"></script> 18<script src="../common/js/jquery.miniColors.js" type="text/javascript"></script> 19<script src="./js/shinobigami.js?20141021" type="text/javascript"></script> 20<script type="text/javascript"> 21 22 var _gaq = _gaq || []; 23 _gaq.push(['_setAccount', 'UA-33727443-1']); 24 _gaq.push(['_trackPageview']); 25 26 (function() { 27 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 28 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 29 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 30 })(); 31 32</script> 33</head> 34<body> 35<div class="noprint"> 36<a href="./">戻る</a><br/> 37<input id="outputText" onclick="createDodontoFText();" type="button" value="どどんとふフォーマット出力"/> 38<input id="outputText" onclick="createReplayText();" type="button" value="リプレイテキスト出力"/> 39<br/> 40</div> 41<form action="" id="chForm" method="post" name="chForm" onsubmit="return false;"> 42<input id="key" name="key" type="hidden"/> 43<input id="jsonData" name="jsonData" type="hidden"/> 44<input id="secretData" name="secretData" type="hidden"/> 45<input id="outline" name="outline" type="hidden"/> 46<div id="title">シノビガミ キャラクターシート</div> 47<div class="error noprint" id="errors"></div> 48<span class="header">基本情報</span><br/> 49... 50... 51
補足情報(FW/ツールのバージョンなど)
- 環境
python 3.6.3
beautifulsoup4 4.7.1
requests 2.21.0
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。