mirror of
https://git.juggalol.com/agatha/stockbot-buyvm.git
synced 2024-11-16 12:46:38 +00:00
Get package objects from HTML
This commit is contained in:
parent
44362f32ab
commit
6c33e418e2
44
main.py
Normal file
44
main.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
"""buyvm stock checker"""
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
|
def get_packages(html):
|
||||||
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
|
packages = []
|
||||||
|
|
||||||
|
package_elements = soup.find_all('div', class_='package')
|
||||||
|
for package_element in package_elements:
|
||||||
|
package = {}
|
||||||
|
|
||||||
|
package_name = package_element.find('h3', class_='package-name').text.strip()
|
||||||
|
package['name'] = package_name
|
||||||
|
|
||||||
|
package_quantity = package_element.find('div', class_='package-qty').text.strip()
|
||||||
|
package['qty'] = package_quantity
|
||||||
|
|
||||||
|
order_button = package_element.find('a', class_='btn-primary')
|
||||||
|
if order_button:
|
||||||
|
order_url = order_button['href']
|
||||||
|
package['url'] = order_url
|
||||||
|
else:
|
||||||
|
package['url'] = ''
|
||||||
|
|
||||||
|
packages.append(package)
|
||||||
|
|
||||||
|
return packages
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with open('tests/data/stock.html', 'r', encoding='utf-8') as file:
|
||||||
|
html = file.read()
|
||||||
|
|
||||||
|
packages = get_packages(html)
|
||||||
|
for package in packages:
|
||||||
|
print('Package Name:', package['name'])
|
||||||
|
print('Package Quantity:', package['qty'])
|
||||||
|
print('Order URL:', package['url'])
|
||||||
|
print('---------------------------')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
beautifulsoup4
|
Loading…
Reference in New Issue
Block a user