{"id":137,"date":"2024-10-31T14:16:30","date_gmt":"2024-10-31T14:16:30","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/a_carpenter\/?p=137"},"modified":"2024-10-31T14:16:30","modified_gmt":"2024-10-31T14:16:30","slug":"html-parsing-and-beautiful-soup","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/a_carpenter\/2024\/10\/31\/html-parsing-and-beautiful-soup\/","title":{"rendered":"Html Parsing and Beautiful Soup"},"content":{"rendered":"\n<p>I have recently been learning Html Parsing and combining it with beautiful soup. The other day I made a stock price scraper that tells you if the price is higher or lower than the last update. Here is the code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from bs4 import BeautifulSoup\nimport requests\nfrom time import sleep\n\nticker = input()\nticker = ticker.upper()\n\nprevious_value = None\n\nwhile True:\n    response = requests.get(f\"https:\/\/www.google.com\/finance\/quote\/{ticker}:NASDAQ?hl=en\")\n    soup = BeautifulSoup(response.text, 'html.parser')\n\n    value = soup.find_all(\"div\", class_=\"YMlKec fxKbKc\")\n    current_value = float(value&#91;0].text.replace(\"$\", \"\"))\n    \n    print(current_value)\n    if previous_value is not None:\n        if current_value > previous_value:\n            print(\"Sell\")\n        elif current_value &lt; previous_value:\n            print(\"Buy\")\n        else:\n            print(\"Hold\")\n    \n    previous_value = current_value\n\n    sleep(10)<\/code><\/pre>\n\n\n\n<p>And what the code does when run:<\/p>\n\n\n\n<p>tsla<br>253.91<br>254.4<br>Sell<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have recently been learning Html Parsing and combining it with beautiful soup. The other day I made a stock price scraper that tells you if the price is higher or lower than the last update. Here is the code: And what the code does when run: tsla253.91254.4Sell<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-137","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/posts\/137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/comments?post=137"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/posts\/137\/revisions"}],"predecessor-version":[{"id":138,"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/posts\/137\/revisions\/138"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/media?parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/categories?post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_carpenter\/wp-json\/wp\/v2\/tags?post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}