0

I want extract some data and put there in excel.

My problem is with extract, I don't take all information than I see with element inspection. With element inspection I see every element, brand, km, price etc... and all of this information are in my extract but in script and not like of what I see in website.

URL of extract : https://www.alcopa-auction.fr/salle-de-vente-encheres/nancy/2110

import requests
from bs4 import BeautifulSoup

URL = 'https://www.alcopa-auction.fr/salle-de-vente-encheres/nancy/2110'
page = requests.get(URL)

headers = {"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'}

page = requests.get(URL, headers=headers)

soup = BeautifulSoup(page.content, 'html.parser')

print(soup)
  • Have you checked whether the missing information is dynamically generated? – AMC Jan 21 '20 at 23:42
  • Does this answer your question? [Python 3: using requests does not get the full content of a web page](https://stackoverflow.com/questions/47730671/python-3-using-requests-does-not-get-the-full-content-of-a-web-page) – AMC Jan 21 '20 at 23:43

1 Answers1

1

The data you see on the page are embedded inside the page in JSON format. You can extract it for example like this:

import re
import json
import requests

url = 'https://www.alcopa-auction.fr/salle-de-vente-encheres/nancy/2110'

txt = requests.get(url).text

json_string = re.search(r'window.Alcopa.searchResultsJSONString = \'(.*)\';', txt)[1]

data = json.loads( json.loads('"{}"'.format(json_string)) )

# print(json.dumps(data, indent=4))  # <-- uncomment this to see all data

print('{:<20} {:<70} {:<10} {:<10} {:<10}'.format('Brand', 'Model', 'Price', 'Sale Date', 'Sale End Date'))
for car in data['car']:
    print('{:<20} {:<70} {:<10} {:<10} {:<10}'.format(car['brand'], car['detailed_model'], car['price'], car['sale_date'], car['sale_end_date']))

Prints:

Brand                Model                                              Price      Sale Date  Sale End Date
RENAULT              TRAFIC L2H1 1200 1.9 DCI 80 PACK CLIM              2 900 €    22/01/2020 22/01/2020
FIAT                 DUCATO COMBI 3.3 M H2 2.2 MULTIJET                 7 000 €    22/01/2020 22/01/2020
CITROEN              C3 HDI 70 CONFORT                                  3 800 €    22/01/2020 22/01/2020
DS                   DS3 HDI 90 FAP AIRDREAM SO CHIC                    4 000 €    22/01/2020 22/01/2020
VOLKSWAGEN           POLO 1.6 TDI 90 CR FAP CONFORTLINE                 3 200 €    22/01/2020 22/01/2020
PEUGEOT              207 1.6 HDI 90CH BLUE LION ACTIVE                  3 100 €    22/01/2020 22/01/2020
FIAT                 PANDA MY 1.2 8V 69 CH TEAM                         1 600 €    22/01/2020 22/01/2020
FORD                 KUGA 2.0 TDCI 140 DPF 4X4 TITANIUM POWERSHIFT A    5 400 €    22/01/2020 22/01/2020

... and so on.
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91