{"id":5082,"date":"2026-08-30T05:40:32","date_gmt":"2026-08-29T20:40:32","guid":{"rendered":"https:\/\/donguri3.net\/server-tech\/python-web-scraping-bikes-availability-2\/"},"modified":"2026-08-30T05:40:34","modified_gmt":"2026-08-29T20:40:34","slug":"python-web-scraping-bikes-availability","status":"publish","type":"post","link":"https:\/\/donguri3.net\/en\/server-tech\/development-programming-git\/python-web-scraping-bikes-availability\/","title":{"rendered":"Automatically Check Delivery Boxes &#038; Electric Bike Availability with Python! An Introduction to Web Scraping"},"content":{"rendered":"<p><span class=\"relative -mx-px my-[-0.2rem] rounded px-px py-[0.2rem] transition-colors duration-100 ease-in-out\">Since it&#8217;s a hassle to access the website every time to check, let&#8217;s create a Python script to check the real-time inventory of FullTime System (rental bicycles \/ delivery boxes, etc.).<\/span><\/p>\n<hr \/>\n<h3>Prerequisites and Legal Considerations<\/h3>\n<ul>\n<li>\n<p><span class=\"relative -mx-px my-[-0.2rem] rounded px-px py-[0.2rem] transition-colors duration-100 ease-in-out\">Set up the Python environment (install <code>requests<\/code> and <code>BeautifulSoup4<\/code>)<\/span><\/p>\n<\/li>\n<li>\n<p><span class=\"relative -mx-px my-[-0.2rem] rounded px-px py-[0.2rem] transition-colors duration-100 ease-in-out\"><span style=\"color: #ff0000;\"><strong>Check robots.txt<\/strong>, <strong>meta robots tags<\/strong>, and <strong>terms of service<\/strong> in advance<\/span> to confirm scraping permission<br \/>\nThis is important<\/span><\/p>\n<\/li>\n<li>\n<p><span class=\"relative -mx-px my-[-0.2rem] rounded px-px py-[0.2rem] transition-colors duration-100 ease-in-out\">Leave intervals between requests to reduce server load<\/span><\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>Script (Fetching Remaining Units)<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">import requests\nfrom bs4 import BeautifulSoup\n\ndef fetch_remaining_bikes(url):\n    resp = requests.get(url)\n    resp.raise_for_status()  # Error check\n\n    soup = BeautifulSoup(resp.text, &quot;html.parser&quot;)\n\n    # Look for a structure like &lt;td class=&quot;count&quot;&gt;5&lt;\/td&gt;\n    # Use find_all if there are multiple facilities\n    td = soup.find(&quot;td&quot;, class_=&quot;count&quot;)\n    if not td:\n        raise ValueError(&quot;Could not find the element for remaining units&quot;)\n\n    count_text = td.get_text(strip=True)\n    try:\n        return int(count_text)\n    except ValueError:\n        raise ValueError(f&quot;Failed to convert to number: {count_text!r}&quot;)\n\nif __name__ == &quot;__main__&quot;:\n    url = &quot;https:\/\/f-cs.jp\/wcsv2\/index.php?id=&lt;DeliveryBoxID&gt;&quot;\n    try:\n        remaining = fetch_remaining_bikes(url)\n        print(f&quot;Remaining electric bikes: {remaining}&quot;)\n    except Exception as e:\n        print(f&quot;An error occurred: {e}&quot;)<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li>\n<p><span class=\"relative -mx-px my-[-0.2rem] rounded px-px py-[0.2rem] transition-colors duration-100 ease-in-out\"><code>requests<\/code> + <code>BeautifulSoup<\/code> <\/span><\/p>\n<\/li>\n<li>\n<p>Since it depends on the HTML structure, you need to verify the class names and other details of the target to be scraped<\/p>\n<\/li>\n<li>Example Execution Result<br \/>\nRemaining electric bikes: 7<\/li>\n<\/ul>\n<hr \/>\n<h3>Conclusion<\/h3>\n<ul>\n<li>\n<p><span class=\"relative -mx-px my-[-0.2rem] rounded px-px py-[0.2rem] transition-colors duration-100 ease-in-out\"><strong>Verify access permissions via robots.txt and meta tags<\/strong><\/span><\/p>\n<\/li>\n<li>\n<p><span class=\"relative -mx-px my-[-0.2rem] rounded px-px py-[0.2rem] transition-colors duration-100 ease-in-out\"><strong>Explicitly specify User-Agent in the request headers<\/strong><\/span><\/p>\n<\/li>\n<li>\n<p><strong>Keep appropriate intervals between requests to avoid overloading<\/strong><\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Since it&#8217;s a hassle to access the website every time to check, let&#8217;s create a Python script to che [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1713,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/donguri3.net\/?p=1710","footnotes":""},"categories":[1172],"tags":[307,52,47,1151],"class_list":["post-5082","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development-programming-git","tag-beautifulsoup","tag-https","tag-python","tag-1151","en-US"],"_links":{"self":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/comments?post=5082"}],"version-history":[{"count":1,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5082\/revisions"}],"predecessor-version":[{"id":5085,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5082\/revisions\/5085"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media\/1713"}],"wp:attachment":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media?parent=5082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/categories?post=5082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/tags?post=5082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}