Задумка в том что бы забрать все ценники с сайта , положить в лист и в последствии запихнуть в json
from email.header import Header
from bs4 import BeautifulSoup
import requests
import json
Headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
}
def get_data(url):
all_links = []
price_game = []
s = requests.Session()
response = s.get(url=url, headers=Headers)
soup = BeautifulSoup(response.text, 'lxml')
pagination = int(soup.find('div', class_="pagination hg-block").find('span', class_="last").find('a').text)
for page in range(1 , 2):
# for page in range(1 , pagination + 1):
url = f"https://hot-game.info/platforms=pc,windows,linux,mac;only_available=1/{page}"
response = s.get(url=url, headers=Headers)
soup = BeautifulSoup(response.text, 'lxml')
all_games = soup.find('section',class_="yui3-cssreset result-block content-table").find_all('div', class_="game-preview hg-block")
for gg in all_games:
link = f"https://hot-game.info{gg.find('a').get('href')}"
all_links.append(link)
with open('links.text' , 'w') as file:
for url in all_links:
file.write(f'{url}\n')
with open('links.text') as file:
urls_list = [line.strip() for line in file.readlines()]
void = []
s = requests.Session()
for url in urls_list:
respons = s.get(url=url, headers=Headers)
soup = BeautifulSoup(respons.text, 'lxml')
name = soup.find('div', class_="hg-block short-game-description").find(itemprop="name").text
all_price = soup.find_all('span', class_="price-value")
for item in all_price:
price = item.text
print(url)
print(name)
print(price)
print('#'* 40)
# for link in link:
# respone = s.get(url= link , headers=Headers)
# soup = BeautifulSoup(response.text, 'lxml')
# print(soup)
def main():
get_data(url='https://hot-game.info/platforms=pc,windows,linux,mac;only_available=1')
if __name__ == '__main__':
main()