получить исключение при запуске цикла поиска супа - PullRequest
0 голосов
/ 16 февраля 2020

Я пытаюсь увидеть, если указать c строку в таблице. поэтому я попытался найти его с супом. найти все. мой код:

for i in soup:
    tmp = soup.findAll("td", {"class": "spec-name"})
    tmp2 = soup.findAll("td", {"class": "spec-value"})
    str1 = tmp[i]
    str2 = tmp[i+1]
    if ('Touch' in str1 and 'yes' in str2 or 'Screen' in str1 and 'YES' in str2):
        IsTouch = "touch screen, "
        FIsTouch = 'yes'
    if ('Touch' in str1 and 'NO' in str2 or 'Screen' in str1 and 'No' in str2):
        IsTouch = "not screen touch"
        FIsTouch = 'no'
        break

я хотел бы увидеть, если "да" встраивается в категорию "touch"

но - я получаю, кроме.

что я делаю не так?

1 Ответ

0 голосов
/ 17 февраля 2020

Мне удалось найти решение с 2 для циклов:

def get_touch(short_desc,tempCat,soup):  
for i in soup.findAll("td", {"class": "spec-name"}):
    tmp=str(i)
    if ('Touch' in tmp or 'touch' in tmp):
        for z in soup.findAll("td", {"class": "spec-value"}):
            tmp2=str(z)
            if('NO' in tmp2 or 'no' in tmp2 or 'No' in tmp2 or 'no' in tmp2):
                IsTouch = "not touch screen, "
                FIsTouch = 'no'
                break
            elif ('YES' in tmp2 or 'yes' in tmp2 or 'Yes' in tmp2):
                IsTouch = "touch screen, "
                FIsTouch = 'yes'
                break
        else:
            continue
...