V
V
Vanya Smolensky2021-07-09 00:47:09
Python
Vanya Smolensky, 2021-07-09 00:47:09

Bug in f Python?

Here is the code

import requests
from bs4 import BeautifulSoup

def get_first_market_steam():
    headers = {
      'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
      'cookie': '_ym_d=1617117545; _ym_uid=161711754528794970; G_ENABLED_IDPS=google; xf_logged_in=1; xf_user=2306008%2C8db46d26a5f78cb04ad8cebd5a7ee6c592170111; timezoneOffset=10800,0; _ga=GA1.1.1292113123.1617117545; xf_last_read_article_date=1617636960; df_id=4edaa88206ca95ffd4e5b6cf693c3d6c; xf_session=eea6a8e176357d0083c7a3df97b42e27; xf_market_items_viewed=14961375%2C15963732%2C15978709%2C15573578%2C15807316; xf_market_search_url=%2Fmarket%2F; _ga_J7RS527GFK=GS1.1.1625692903.224.1.1625702146.0'
    }

    url = 'https://lolz.guru/market/steam/'
    r = requests.get(url=url, headers=headers)

    soup = BeautifulSoup(r.text, 'lxml')
    markets_cards = soup.find_all('div', class_='marketIndexItem')
    print(market_cards)

    for market in markets_cards:
    	  market_title = soup.find('a', class_='marketIndexItem--Title').text.strip()
    	  market_info = soup.find('div', class_='marketIndexItem--Badges stats').text.strip()
    	  market_infogame = soup.find('div', class_='marketIndexItem--Badges').text.strip()
    	  market_infouser = soup.find('div', class_='marketIndexItem--otherInfo').text.strip()
    	  market_url = f'https://lolz.guru/{market.get('href')}'


    	  print (f'{market_title} | {market_info} | {market_infogame} | {market_infouser} | {market_url}')


get_first_market_steam()


Here is the error
line 22
    market_url = f'https://lolz.guru/{market.get('href')}'
                                                  ^
SyntaxError: f-string: unmatched '('


Tried to google it and couldn't find it

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2021-07-09
@Animsall

Even code highlighting tells you the problem.

V
Vasily Bannikov, 2021-07-09
@vabka

The python parser is as stupid as possible, so you cannot use the quote character inside formatted strings.
If you write like this:

href = market.get('href')
market_url = f'https://lolz.guru/{href}'

that will be ok

L
lerotyck, 2021-07-09
@lerotyck

Use double quotes instead of single quotes f'https://lolz.guru/{market.get('href')}'
f"https://lolz.guru/{market.get('href')}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question