請幫幫我!我編寫了一個簡單的解析器,但它不能正常工作,我不知道這與什么有關。import requestsfrom bs4 import BeautifulSoupURL = 'https://stopgame.ru//topgames'HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0', 'accept': '*/*'}HOST = 'https://stopgame.ru'def get_html(url, params=None): r = requests.get(url, headers=HEADERS, params=params) return rdef get_content(html): soup = BeautifulSoup(html, 'html.parser') items = soup.find_all('a', class_="lent-block game-block") print(items)def parse(): html = get_html(URL) if html.status_code == 200: items = get_content(html.text) else: print('Error')parse()我有這個輸出:[]Process finished with exit code 0
1 回答

慕娘9325324
TA貢獻1783條經驗 獲得超4個贊
items = soup.find_all('a', class_="lent-block game-block")
您正在嘗試找出 html 中實際上不存在的錨標記的“lent-block game-block”類,因此您得到的是空白列表。
嘗試使用此 div 項目,您將獲得匹配項目的列表。
items = soup.find_all('div', class_="lent-block lent-main")
添加回答
舉報
0/150
提交
取消