【发布时间】:2021-03-18 05:11:56
【问题描述】:
我的问题是,它会遍历页面,但它不会在我的列表中写入任何内容。
最后我打印len(title),它仍然是0。
from bs4 import BeautifulSoup
import requests
for page in range(20, 200, 20):
current_page = 'https://auto.bazos.sk/{}/?hledat=kolesa&hlokalita=&humkreis=&cen'.format(page)
web_req = requests.get(current_page).text
soup = BeautifulSoup(requests.get(current_page).content, 'html.parser')
title_data = soup.select('.nadpis')
title = []
for each_title in title_data:
title.append(each_title.text)
print(current_page)
print(len(title))
【问题讨论】:
-
打印 each_title.text 会发生什么?如果这是预期的文本内容,您的 .append 方法可能有问题。如果没有,请尝试打印其来源等以找到根本原因
标签: python web web-scraping beautifulsoup