您的数据似乎以 JSON 格式编码在 HTML 页面中(BeautifulSoup 无法帮助您,但您可以使用 re 模块提取数据):
import re
import json
import requests
from pprint import pprint
url = 'https://www.astm.org/search/fullsite-search.html?query=alloy&toplevel=products-and-services&sublevel=standards-and-publications'
data = json.loads(re.findall(r'var mc_results = ({.*?})\s*;', requests.get(url, verify=False).text, flags=re.DOTALL)[0])
for s in data['resSet']:
for result in s['results']:
pprint(result['res']['meta'])
print('*' * 80)
打印:
{'gs_designation': 'A506',
'gs_homebook': '0103 CS01',
'gs_year': '16',
'mc_addtocart': 'PDF-A506',
'mc_date': '2016',
'mc_dltype': 'allstd,active,basecompass',
'mc_doctype': 'Active Standard',
'mc_doi': 'A0506-16',
'mc_icsdata': '77.140.50 (Flat steel products and semi-products)',
'mc_keywordsen': 'cold-rolled steel products~ hot-rolled steel products~ ',
'mc_language': 'English',
'mc_login': 'true',
'mc_maincat': 'standard,sedl',
'mc_maincomm': 'A01',
'mc_relatedurl': 'A506_related.htm',
'mc_section': '01',
'mc_sectors': 'Metals',
'mc_sublevel': 'standards-and-publications,sedl-digital-library',
'mc_suburl': '/SUBSCRIPTION/filtrexx40.cgi?+/usr6/htdocs/newpilot.com/SUBSCRIPTION/REDLINE_PAGES/A506.htm',
'mc_tax0': 'Properties_and_Measurements,Test_Methods,Materials',
'mc_tax1': 'Chemical_Properties,Mechanical_Test,Metals_--_Iron_and_Alloys',
'mc_tax2': 'Chemical_Composition,Fractography,Tensile_Test,Steel,Iron_and_Steel_Products',
'mc_tax3': 'Hardness_Test,Alloy_Steel,Flat_Products,Specialty_Steel',
'mc_tax4': 'Structural_Steel',
'mc_taxkeywordsen': 'Alloy Steel,Flat Products,Structural Steel,Chemical '
'Composition,Hardness Test,Tensile Test',
'mc_tertiary': 'standards-products',
'mc_toplevel': 'products-and-services',
'mc_unspscdata': '30264100(Steel alloy sheets)',
'title': 'Standard Specification for Alloy and Structural Alloy Steel, Sheet '
'and Strip, Hot-Rolled and Cold-Rolled'}
********************************************************************************
{'gs_designation': 'B768',
'gs_homebook': '0201 CS02',
'gs_year': '11(2016)',
'mc_addtocart': 'PDF-B768',
'mc_date': '2016',
'mc_dltype': 'allstd,active,basecompass',
'mc_doctype': 'Active Standard',
'mc_doi': 'B0768-11R16',
...and so on.