0

So I am trying to get into python, and am using other examples that I find online to understand certain functions better.

I found a post online that shared a way to check prices on an item through CamelCamelCamel.

They had it set to request from a specific url, so I decided to change it to userinput instead.

How can I just simply loop this function?

It runs fine afaik once, but after the inital process i get 'Process finished with exit code 0', which isn't necessarily a problem.

For the script to perform how I would like it to. It would be nice if there was a break from maybe, 'quit' or something, but after it processes the URL that was given, I would like it to request for a new URL. Im sure theres a way to check for a specific url, IE this should only work for Camelcamelcamel, so to limit to only that domain.

Im more familiar with Batch, and have kinda gotten away with using batch to run my python files to circumvent what I dont understand.

Personally if I could . . .

I would just mark the funct as 'top:'

and put goto top at the bottom of the script.

from bs4 import BeautifulSoup
import requests

print("Enter CamelCamelCamel Link: ") 
plink    = input("") 

headers = {'User-Agent': 'Mozilla/5.0'} 
r = requests.get(plink,headers=headers) 

data = r.text 
soup = BeautifulSoup(data,'html.parser') 
table_data = soup.select('table.product_pane tbody tr td') 


hprice = table_data[1].string
hdate = table_data[2].string
lprice = table_data[7].string
ldate = table_data[8].string 

print ('High price-',hprice)
print ("[H-Date]", hdate)
print ('---------------')
print ('Low price-',lprice)
print ("[L-Date]", ldate)

Also how could I find the difference from the date I obtain from either hdate or ldate, from today/now. How the dates I parsed they're strings and I got. TypeError: unsupported operand type(s) for +=: 'int' and 'str'.

This is really just for learning, any example works, It doesnt have to be that site in specific.

  • Goto? **>_<** How many times are you trying to repeat the same action? – J. Murray Oct 09 '19 at 21:46
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [Minimal, complete, verifiable example](https://stackoverflow.com/help/minimal-reproducible-example) applies here. We cannot effectively help you until you post your MCVE code and accurately specify the problem. We should be able to paste your posted code into a text file and reproduce the problem you specified. – Prune Oct 09 '19 at 21:48
  • Also refer to [on topic](https://stackoverflow.com/help/on-topic), [how to ask](https://stackoverflow.com/help/how-to-ask), and ... [the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). StackOverflow is not a design, coding, research, or tutorial resource; you're asking a variety of questions under one heading, and too general to make a good posting here. – Prune Oct 09 '19 at 21:49
  • Put `while True:` at the beginning of the code that should loop. If the user enters `quit`, use `break` to stop the loop. – Barmar Oct 09 '19 at 21:50
  • @J. Murray as many times as a user inputs a url that matches, or types 'exit' or is manually closed. – Spencer Ritter Oct 09 '19 at 22:05
  • @Barmar ty I have seen this referenced in other places, but I wasnt sure if that was exclusive to math formulas. – Spencer Ritter Oct 09 '19 at 22:06
  • Why would it be exclusive to math? You're overthinking it. A loop is a loop. – Barmar Oct 09 '19 at 22:07

1 Answers1

1

In Python, you have access to several different types of looping control structures, including:

  1. while statements

    while (condition) # Will execute until condition is no longer True (or until break is called)
       <statements to execute while looping>
    
  2. for statements

    for i in range(10) # Will execute 10 times (or until break is called)
       <statements to execute while looping>
    

    Each one has its strengths and weaknesses, and the documentation at Python.org is very thorough but easy to assimilate.

https://docs.python.org/3/tutorial/controlflow.html

J. Murray
  • 1,460
  • 11
  • 19