【发布时间】:2019-07-26 03:27:47
【问题描述】:
我怎样才能获得同一网站“https://www.sfma.org.sg/member/category”的每个列表页面上提到的所有类别。例如,当我在上述页面上选择酒精饮料类别时,该页面上提到的列表具有这样的类别信息:-
Catergory: Alcoholic Beverage, Bottled Beverage, Spirit / Liquor / Hard Liquor, Wine, Distributor, Exporter, Importer, Supplier
我怎样才能用相同的变量提取这里提到的类别。
我为此编写的代码是:-
category = soup_2.find_all('a', attrs ={'class' :'plink'})
links = [links['href'] for links in category]
但它正在生成以下输出,这些输出是页面上的所有链接,而不是 href 中的文本:-
['http://www.sfma.org.sg/about/singapore-food-manufacturers-association',
'http://www.sfma.org.sg/about/council-members',
'http://www.sfma.org.sg/about/history-and-milestones',
'http://www.sfma.org.sg/membership/',
'http://www.sfma.org.sg/member/',
'http://www.sfma.org.sg/member/alphabet/',
'http://www.sfma.org.sg/member/category/',
'http://www.sfma.org.sg/resources/sme-portal',
'http://www.sfma.org.sg/resources/setting-up-food-establishments-in-singapore',
'http://www.sfma.org.sg/resources/import-export-requirements-and-procedures',
'http://www.sfma.org.sg/resources/labelling-guidelines',
'http://www.sfma.org.sg/resources/wsq-continuing-education-modular-programmes',
'http://www.sfma.org.sg/resources/holistic-industry-productivity-scorecard',
'http://www.sfma.org.sg/resources/p-max',
'http://www.sfma.org.sg/event/',
.....]
如果问题似乎是新手,请原谅,我对python很陌生,
谢谢!!!
【问题讨论】:
标签: python html python-3.x web-scraping beautifulsoup