34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import requests, bs4, urllib, sys, re, math
|
|
|
|
url = str(sys.argv[1]);
|
|
|
|
headers = {
|
|
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36',
|
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
|
|
'Upgrade-Insecure-Requests': '1',
|
|
'save-data': 'on',
|
|
'Host': 'www.grainger.com'
|
|
}
|
|
|
|
resp = requests.get(url, headers = headers)
|
|
resp.raise_for_status()
|
|
resp.encoding='UTF-8'
|
|
|
|
html = resp.text
|
|
|
|
bs = bs4.BeautifulSoup(html, 'html.parser')
|
|
|
|
prdName = bs.select('div#productPage div h1.productName')[0].getText().strip()
|
|
zoomIMG = bs.select('img#mainImageZoom')[0]['data-blzsrc']
|
|
zoomIMG = 'https:' + re.sub('\$mdmain\$','$zmmain$',zoomIMG)
|
|
|
|
techSpecsName = bs.select('div.techSpecsTable ul li span.specName')
|
|
techSpecsValue = bs.select('div.techSpecsTable ul li span.specValue')
|
|
|
|
for i in range(len(techSpecsName)) :
|
|
name = techSpecsName[i].getText().strip()
|
|
value = techSpecsValue[i].getText().strip()
|
|
if name != '' :
|
|
print(prdName + "\t" + url + "\t" + name + "\t" + value)
|