Issue
import requests
from bs4 import BeautifulSoup
import json
headers = {
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8,pt;q=0.7',
'Connection': 'keep-alive',
'Origin': 'https://www.nationalhardwareshow.com',
'Referer': 'https://www.nationalhardwareshow.com/',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site',
'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',
'accept': 'application/json',
'content-type': 'application/x-www-form-urlencoded',
'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
base_url='https://api.reedexpo.com/v1/organisations/'
params = {
'x-algolia-agent': 'Algolia for vanilla JavaScript 3.27.1',
'x-algolia-application-id': 'XD0U5M6Y4R',
'x-algolia-api-key': 'd5cd7d4ec26134ff4a34d736a7f9ad47',
}
data = '{"params":"query=&page=0&facetFilters=&optionalFilters=%5B%5D"}'
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()
productlinks=[]
for item in resp['hits']:
url=base_url+item['organisationGuid']+"/exhibiting-organisations?eventEditionId="+item['eventEditionExternalId']
productlinks.append(url)
for link in productlinks:
title=link['_embedded']['companyName'].json()
print(title)
I am trying to get data but they show me str must be integer
these is the page link where I get json https://www.nationalhardwareshow.com/en-us/attend/exhibitor-list/exhibitor-details.org-8e39ea94-5500-4798-8fe6-b8fab875dd87.html#
Solution
Try these it will work for you:
import requests
from bs4 import BeautifulSoup
import json
headers = {
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8,pt;q=0.7',
'Connection': 'keep-alive',
'Origin': 'https://www.nationalhardwareshow.com',
'Referer': 'https://www.nationalhardwareshow.com/',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site',
'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',
'accept': 'application/json',
'content-type': 'application/x-www-form-urlencoded',
'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
base_url='https://api.reedexpo.com/v1/organisations/'
params = {
'x-algolia-agent': 'Algolia for vanilla JavaScript 3.27.1',
'x-algolia-application-id': 'XD0U5M6Y4R',
'x-algolia-api-key': 'd5cd7d4ec26134ff4a34d736a7f9ad47',
}
data = '{"params":"query=&page=0&facetFilters=&optionalFilters=%5B%5D"}'
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()
productlinks=[]
for item in resp['hits']:
url=base_url+item['organisationGuid']+"/exhibiting-organisations?eventEditionId="+item['eventEditionExternalId']
productlinks.append(url)
for link in productlinks:
headers = {"x-clientid": "uhQVcmxLwXAjVtVpTvoerERiZSsNz0om"}
data = requests.get(link, headers=headers).json()
for t in data["_embedded"]:
d=t["multilingual"]
for u in d:
k=u["address"]
print(k)
output:
{'addressLine1': '2950 Fretz Valley Rd', 'addressLine2': '', 'city': 'Perkasie', 'stateProvince': 'PA', 'postcode': '18944-4034', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': '304 Rio Del Norte Road', 'addressLine2': '', 'city': 'St. Augustine', 'stateProvince': 'Florida', 'postcode': '32095', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': '1752 Anklam Ct.', 'addressLine2': '', 'city': 'Rio Rico', 'stateProvince': 'Arizona', 'postcode': '85648', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': '56965 Panchita Road', 'addressLine2': '', 'city': 'Yucca Valley', 'stateProvince': 'California', 'postcode': '92284', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': '10887 Commerce Way Unit A', 'addressLine2': '', 'city': 'Fontana', 'stateProvince': 'California', 'postcode': '92337', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': '14832 Arrow Hwy', 'addressLine2': '', 'city': 'Baldwin Park', 'stateProvince': 'CA', 'postcode': '91706-1823', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': 'No.99 Haixi Road', 'addressLine2': 'Jiaonan Qingdao', 'city': 'Qingdao', 'stateProvince': 'Shandong', 'postcode': '266400', 'countryCode': 'CHN', 'country': 'China'}
{'addressLine1': '1 John C Dean Memorial Blvd', 'addressLine2': '', 'city': 'Cumberland', 'stateProvince': 'RI', 'postcode': '02864-4801', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': '2 Marlborough Rd', 'addressLine2': '', 'city': 'West Hempstead', 'stateProvince': 'NY', 'postcode': '11552-1712', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': 'Near Kmv College', 'addressLine2': 'Tanda Road', 'city': 'Jalandhar', 'stateProvince': 'Punjab', 'postcode': '144004', 'countryCode': 'IND', 'country': 'India'}
{'addressLine1': '809 S Hamilton St', 'addressLine2': '', 'city': 'Sullivan', 'stateProvince': 'IL', 'postcode': '61951-2209', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': '2924 State Highway 155', 'addressLine2': '', 'city': 'Sayner', 'stateProvince': 'Wisconsin', 'postcode': '54560', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': '99 Madison Ave Fl 620', 'addressLine2': '', 'city': 'New York', 'stateProvince': 'NY', 'postcode': '10016-7419', 'countryCode': 'USA', 'country': 'United States'}
{'addressLine1': 'E-5, MIDC', 'addressLine2': 'Waluj', 'city': 'Aurangabad', 'stateProvince': 'Maharashtra', 'postcode': '431136', 'countryCode': 'IND', 'country': 'India'}
Answered By - Arslan Aziz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.