ошибка SyntaxError: invalid syntax

slavon141

Новичок
Пользователь
Окт 13, 2020
2
0
1
только начал изучать Питон. делаю парсер. не пойму в чем причина ошибки
пипы:
beautifulsoup4 4.9.3
requests 2.24.0


C:\Users\user3\AppData\Local\Programs\Python\Python39\python.exe C:/bottest/bot.py
File "C:\bottest\bot.py", line 21
'link': item.find('a', class_='c-events__name').get.('href')
^
SyntaxError: invalid syntax

Process finished with exit code 1

без строки 'link': item.find('a', class_='c-events__name').get.('href') все ок, но мне нужно найти ссылки на матчи


Python:
import requests
from bs4 import BeautifulSoup

URL = 'https://ua-1x-bet.com/ua/line/Basketball/'
HEADERS = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0' , 'accept': '*/*'}

def get_html(url, params=None):
    r = requests.get(url, headers=HEADERS, params=params)
    return r


def get_content(html) :
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.find_all('a', class_='c-events__name')


    events = []
    for item in items:
        events.append({
            'title': item.find('span', class_='c-events__teams').get_text()
            'link': item.find('a', class_='c-events__name').get.('href')


        })
        print(events)



def parse():
    html = get_html(URL)
    if html.status_code == 200:
        get_content(html.text)
    else:
        print('Error')

parse()
 
Последнее редактирование:

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 590
460
83
пропуск запятой и лишняя точка
Python:
def get_content(html) :
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.find_all('a', class_='c-events__name')


    events = []
    for item in items:
        events.append({
            'title': item.find('span', class_='c-events__teams').get_text(),
            'link': item.find('a', class_='c-events__name').get('href')


        })
        print(events)
 
  • Мне нравится
Реакции: slavon141

slavon141

Новичок
Пользователь
Окт 13, 2020
2
0
1
пропуск запятой и лишняя точка
Python:
def get_content(html) :
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.find_all('a', class_='c-events__name')


    events = []
    for item in items:
        events.append({
            'title': item.find('span', class_='c-events__teams').get_text(),
            'link': item.find('a', class_='c-events__name').get('href')


        })
        print(events)
Спасибо)) но когда исправил вылазит вторая ошибка AttributeError: 'NoneType' object has no attribute 'get' "сча" буду гуглить))

уже нашел. не то парсил в find all
 
Последнее редактирование:

lynulx

Модератор
Команда форума
Модератор
Авг 9, 2020
139
19
18
только начал изучать Питон. делаю парсер. не пойму в чем причина ошибки
пипы:
beautifulsoup4 4.9.3
requests 2.24.0


C:\Users\user3\AppData\Local\Programs\Python\Python39\python.exe C:/bottest/bot.py
File "C:\bottest\bot.py", line 21
'link': item.find('a', class_='c-events__name').get.('href')
^
SyntaxError: invalid syntax

Process finished with exit code 1

без строки 'link': item.find('a', class_='c-events__name').get.('href') все ок, но мне нужно найти ссылки на матчи


Python:
import requests
from bs4 import BeautifulSoup

URL = 'https://ua-1x-bet.com/ua/line/Basketball/'
HEADERS = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0' , 'accept': '*/*'}

def get_html(url, params=None):
    r = requests.get(url, headers=HEADERS, params=params)
    return r


def get_content(html) :
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.find_all('a', class_='c-events__name')


    events = []
    for item in items:
        events.append({
            'title': item.find('span', class_='c-events__teams').get_text()
            'link': item.find('a', class_='c-events__name').get.('href')


        })
        print(events)



def parse():
    html = get_html(URL)
    if html.status_code == 200:
        get_content(html.text)
    else:
        print('Error')

parse()
в списки нельзя добавлять в таком виде, делайте словарь и добавляйте в виде
events["title"] =...
events["link"] = ...
 

Форум IT Специалистов