Я хочу взять 2 данных в «td», «Barcode» и «nama produk», но получаю очень плохие данные. что мне исправить?
Код: Выделить всё
import csv
import requests
from bs4 import BeautifulSoup
outfile = open("dataaa.csv","w",newline='')
writer = csv.writer(outfile)
page = 0
while page < 3 :
url = "http://ciumi.com/cspos/barcode-ritel.php?page={:d}".format(page)
response = requests.get(url)
tree = BeautifulSoup(response.text, 'html.parser')
page += 1
table_tag = tree.select("table")[0]
tab_data = [[item.text for item in row_data.select("tr")]
for row_data in table_tag.select("td")]
for data in tab_data:
writer.writerow(data)
print(table_tag)
print(response, url, ' '.join(data))
import fileinput
seen = set()
for line in fileinput.FileInput('dataaa.csv', inplace=1):
if line in seen: continue
seen.add(line)
print (line)
Подробнее здесь: https://stackoverflow.com/questions/578 ... on-and-bs4