所以我从这个链接中取了药物的名称:药物列表
现在我想获得每种药物的内容,同时每种药物都有自己的链接示例:medicines示例
如何使用beautifulsoup4和请求库获取该药物的内容?
import requests
from bs4 import BeautifulSoup
from pprint import pp
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0'
}
def main(url):
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.text, 'lxml')
title = [x.text for x in soup.select(
'a[class$=section__item-link]')]
count = 0
for x in range (0, len(title)):
count += 1
print("{0}. {1}\n".format(count, title[x]))
main('https://www.klikdokter.com/obat')
1条答案
按热度按时间zzwlnbp81#
根据我所看到的来自https://www.klikdokter.com/obat 您应该能够执行以下操作:-