У меня есть html выдержка ниже, обратите внимание, повторение двух тд для каждой строки, которую мне нужно захватить.
<table class="ent">
<tbody class=""><tr class="tablestyle">
<td class="hide_on_mobile"> <a href="../" class="">
<img class="ProductImage" src="https://.."></a>
</td>
<td class="hide_on_mobile" align="center">
<strong class="">
<span style="font-size:1.4em;" class="">Scraped okay - col0</span>
<br>
<br>Scrape this text - col1</strong><br>
<br><i><span style="color:indigo;" class="">Scrape this text - col2
<br class="">
<br>Next Event: Scrape this text -col3</span></i>
</td>
Мне нужно захватить 4 разных фрагмента данных col0, col1, col2, col3
У меня уже работает col0.Мне нужно захватить col1, col2, col3
Я пытаюсь использовать BR, то есть после span
взять текст после 2-го BR после col1
взять текстпосле 3-го BR после для col2
взять текст после 5-го BR после для col3
Я не могу заставить col1 работать с br> br.Любые идеи, как я могу решить это?
import sqlite3
import datetime
import requestsnt
import pandas as pd
from bs4 import BeautifulSoup
url = "http:/*"
r = requests.get(url)
source = r.text
t = datetime.datetime.now().date()
soup = BeautifulSoup(source, "lxml")
row_count=200
row_marker = 0
new_table = pd.DataFrame(columns = ["col0", "col1", "col2","col3", "DateAdded"], index = range(0,row_count)) # I don't know the number of rows
# For col0
column_marker = 0
for layout in soup.select("strong > span"):
new_table.iat[row_marker,column_marker] = layout.text.strip()
new_table.iat[row_marker,4] = t
row_marker +=1
# For col 1
column_marker = 1
row_marker = 0
for layout in soup.select("strong > span > br > br"):
new_table.iat[row_marker,column_marker] = layout.text.strip()
row_marker +=1