They show me error that AttributeError: 'dict' object has no attribute 'append'
how to handle these error when trying to append the data I am creating a loop in order to append continuously values from user input to a dictionary but i am getting this error is any method to show solve these error this is page link https://www.nationalhardwareshow.com/en-us/attend/exhibitor-list.html:
JavaScript
x
61
61
1
import requests
2
from bs4 import BeautifulSoup
3
import json
4
import pandas as pd
5
headers = {
6
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8,pt;q=0.7',
7
'Connection': 'keep-alive',
8
'Origin': 'https://www.nationalhardwareshow.com',
9
'Referer': 'https://www.nationalhardwareshow.com/',
10
'Sec-Fetch-Dest': 'empty',
11
'Sec-Fetch-Mode': 'cors',
12
'Sec-Fetch-Site': 'cross-site',
13
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
14
'accept': 'application/json',
15
'content-type': 'application/x-www-form-urlencoded',
16
'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
17
'sec-ch-ua-mobile': '?0',
18
'sec-ch-ua-platform': '"Windows"',
19
}
20
base_url='https://api.reedexpo.com/v1/organisations/'
21
22
params = {
23
'x-algolia-agent': 'Algolia for vanilla JavaScript 3.27.1',
24
'x-algolia-application-id': 'XD0U5M6Y4R',
25
'x-algolia-api-key': 'd5cd7d4ec26134ff4a34d736a7f9ad47',
26
}
27
28
data = '{"params":"query=&page=0&facetFilters=&optionalFilters=%5B%5D"}'
29
30
resp = requests.post('https://xd0u5m6y4r-3.algolianet.com/1/indexes/event-edition-eve-e6b1ae25-5b9f-457b-83b3-335667332366_en-us/query', params=params, headers=headers, data=data).json()
31
productlinks=[]
32
for item in resp['hits']:
33
url=base_url+item['organisationGuid']+"/exhibiting-organisations?eventEditionId="+item['eventEditionExternalId']
34
productlinks.append(url)
35
36
data=[]
37
for link in productlinks:
38
headers = {"x-clientid": "uhQVcmxLwXAjVtVpTvoerERiZSsNz0om"}
39
data = requests.get(link, headers=headers).json()
40
wev={}
41
for t in data["_embedded"]:
42
name=t['companyName']
43
wev['name']=name
44
email=t['email']
45
wev['Email']=email
46
telephone=t["phone"]
47
wev['Telephone']=telephone
48
link=t['website']
49
wev['link']=link
50
d=t["multilingual"]
51
for u in d:
52
k=u["address"]
53
wev['address']=k
54
n=u["representedBrands"]
55
wev['brand']=n
56
57
data.append(wev)
58
59
df=pd.DataFrame(data)
60
print(df)
61
Advertisement
Answer
Your issue is that you initialise data
as a list and reassign to a dict
data structure. Use different variables for different purposes instead:
JavaScript
1
8
1
store = []
2
for link in productlinks:
3
data = requests.get("...").json()
4
# process data ...
5
store.append(data)
6
7
df = pd.DataFrame(store)
8