Я пытаюсь очистить некоторую часть страницы: https://tuning-tec.com/mercedes_w164_ml_mklasa_0507_black_led_seq_lpmed0-5789i
Чтобы найти описание элементов, вы можете войти на страницу, как показано ниже: https://tuning-tec.com/_template/_show_normal/_show_charlong.php?itemId=5789
Теперь мне нужно получить часть engli sh description
Итак, я пытаюсь получить элементы по td в выбранной строке следующим образом:
import re
import requests
from bs4 import BeautifulSoup
url = 'https://tuning-tec.com/mercedes_w164_ml_mklasa_0507_black_led_seq_lpmed0-5789i'
ajax_url = 'https://tuning-tec.com/_template/_show_normal/_show_charlong.php?itemId={}'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
item_id = re.findall(r"ajax_update_stat\('(\d+)'\)", soup.text)[0]
soup2 = BeautifulSoup(requests.get(ajax_url.format(item_id)).content, 'html.parser')
def unwrapElements(soup, elementsToFind):
elements = soup.find_all(elementsToFind)
for element in elements:
element.unwrap()
#Get content what i need (find tr and get seconnd td where is english description)
description=soup2.findAll('tr')[1].findAll('td')[1]
description.append(soup2.new_tag('br'))
description.append((soup2.findAll('tr')[2].findAll('td')[1]))
description.append(soup2.findAll('tr')[3].findAll('td')[1])
description.append(soup2.new_tag('br'))
description.append(soup2.findAll('tr')[4].findAll('td')[1])
#Remove tags what I dont wont
unwrapElements(description, "font")
unwrapElements(description, "span")
unwrapElements(description, "strong")
unwrapElements(description, "b")
unwrapElements(description, "td")
print(description)
Я так близко, чтобы получить хороший вывод я добавляю немного "BR", чтобы разбить новую строку, но я вижу несколько пробелов между
<td>Description<br/>Projector
headlights with LED Parking
light.<br/>With Dynamic Turn
Signal.<br/>100% brand new, come in pair
(left & right).<br/>Approval:
E-marked E13 - approved. Details<br/>Parking
light: LED<br/>Blinker: LED
<br/>Low
beam: H9 included <br/>High beam:
H1 included <br/>Regulation: electrical (with build in
electrical adjuster).</td>
И когда я ставлю его на html, я вижу "Â":
DescriptionProjector headlights with LED Parking light.
With Dynamic Turn Signal.
100% brand new, come in pair (left & right).
Approval: E-marked E13 - approved. DetailsParking light: LED
Blinker:Â LED
Low beam:Â H9Â Â Â includedÂ
High beam: H1Â Â Â includedÂ
Regulation: electrical (with build in electrical adjuster).
Как Я могу это исправить?
И второй вопрос.
Почему в выводе есть td, когда я разворачиваю теги?