{"id":2060,"date":"2020-09-08T22:55:08","date_gmt":"2020-09-08T13:55:08","guid":{"rendered":"https:\/\/obenkyolab.com\/?p=2060"},"modified":"2021-06-05T23:49:36","modified_gmt":"2021-06-05T14:49:36","slug":"%e3%80%90python%e3%80%91pandas%e3%81%a7html%e3%81%aetable%e3%82%92%e3%82%b9%e3%82%af%e3%83%ac%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0","status":"publish","type":"post","link":"https:\/\/obenkyolab.com\/?p=2060","title":{"rendered":"\u3010Python\u3011pandas\u3067html\u306etable\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/obenkyolab.com\/?p=2060\/#%E6%A6%82%E8%A6%81\" >\u6982\u8981<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/obenkyolab.com\/?p=2060\/#table%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E3%82%B3%E3%83%BC%E3%83%89\" >table\u3092\u53d6\u5f97\u3059\u308b\u30b3\u30fc\u30c9<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A6%82%E8%A6%81\"><\/span>\u6982\u8981<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u3067BeautifulSoup\u3092\u4f7f\u3063\u3066web\u30da\u30fc\u30b8\u306ehtml\u304b\u3089table\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3057\u305f\u3068\u304d\u306b\u5c11\u3057\u306f\u307e\u3063\u305f\u3068\u304d\u306e\u5bfe\u51e6\u6cd5\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3057\u305f\u304c\u3001pandas\u3092\u4f7f\u3063\u305f\u3089\u305d\u3093\u306a\u3053\u3068\u60a9\u3093\u3060\u6642\u9593\u304c\u4f55\u3060\u3063\u305f\u3093\u3060\u308d\u3046\u3068\u3044\u3046\u304f\u3089\u3044\u4e00\u77ac\u3067\u3067\u304d\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u30e1\u30e2\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-it-learning\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"GLDqVS1EwV\"><a href=\"https:\/\/obenkyolab.com\/?p=2054\">\u3010Python\u3011BeautifulSoup\u3067table\u304c\u6700\u521d\u306e\u6570\u884c\u3057\u304b\u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408\u306e\u5bfe\u51e6<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;\u3010Python\u3011BeautifulSoup\u3067table\u304c\u6700\u521d\u306e\u6570\u884c\u3057\u304b\u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408\u306e\u5bfe\u51e6&#8221; &#8212; Obenkyolab\" src=\"https:\/\/obenkyolab.com\/?p=2054&#038;embed=true#?secret=fnbsAB62CD#?secret=GLDqVS1EwV\" data-secret=\"GLDqVS1EwV\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"table%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E3%82%B3%E3%83%BC%E3%83%89\"><\/span>table\u3092\u53d6\u5f97\u3059\u308b\u30b3\u30fc\u30c9<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"text-decoration: underline;\">BeautifulSoup\u3092\u4f7f\u3046\u5834\u5408<\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport requests\nfrom bs4 import BeautifulSoup\n \nr = requests.get(&#039;http:\/\/example.com&#039;,headers = headers)\nsoup = BeautifulSoup(r.content, &quot;lxml&quot;)\n \ntable = soup.findAll(&#039;table&#039;,{&#039;class&#039;:&quot;test_table&quot;})&#x5B;0]\n \nrows = table.findAll(&#039;tr&#039;)\nfor row in rows:\n    print(row)\n<\/pre><\/div>\n\n\n<p><span style=\"text-decoration: underline;\">pandas\u3092\u4f7f\u3046\u5834\u5408<\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport pandas as pd\n\nurl = &#039;http:\/\/example.com&#039;\ndf = pd.read_html(url)\nprint(df&#x5B;0])\n<\/pre><\/div>\n\n\n<p>pandas\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u5f97\u3089\u308c\u308b\u30c7\u30fc\u30bf\u5f62\u5f0f\u304cDataFrame\u3067\u3059\u304c\u3001python\u3067\u8868\u3092\u6271\u3046\u5834\u5408\u306f\u6700\u521d\u304b\u3089DataFrame\u3067\u3068\u308c\u305f\u307b\u3046\u304c\u6709\u96e3\u3044\u306e\u3067\u5168\u304f\u554f\u984c\u7121\u3057\u3002\u4eca\u5f8c\u3069\u3093\u3069\u3093\u4f7f\u3063\u3066\u3044\u3063\u3066\u30c7\u30e1\u30ea\u30c3\u30c8\u3068\u304b\u3042\u308b\u304b\u306f\u8abf\u3079\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4ee5\u4e0a<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Python\u3092\u4e00\u304b\u3089\u5b66\u3076\u306e\u306b\u304a\u3059\u3059\u3081\u306e\u672c\u306f\u30b3\u30c1\u30e9<\/span><\/strong><\/p>\n\n\n\n<iframe style=\"width:120px;height:240px;\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" frameborder=\"0\" src=\"https:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?ref=qf_sp_asin_til&#038;t=sebone0f-22&#038;m=amazon&#038;o=9&#038;p=8&#038;l=as1&#038;IS2=1&#038;detail=1&#038;asins=4873117380&#038;linkId=665846163826975f4858844e1483e9e7&#038;bc1=000000&amp;lt1=_blank&#038;fc1=333333&#038;lc1=0066c0&#038;bg1=ffffff&#038;f=ifr\">\n    <\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 \u4ee5\u4e0b\u3067BeautifulSoup\u3092\u4f7f\u3063\u3066web\u30da\u30fc\u30b8\u306ehtml&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/obenkyolab.com\/?p=2060","footnotes":""},"categories":[7],"tags":[],"class_list":["post-2060","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","ja"],"_links":{"self":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/2060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2060"}],"version-history":[{"count":2,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/2060\/revisions"}],"predecessor-version":[{"id":2903,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/2060\/revisions\/2903"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/media\/1218"}],"wp:attachment":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}