В этом случае я хочу получить URL-адрес типа «https:// . . .» но результатом является список в переменной link, содержащий все ссылки в сети. Вот код ниже;
Код: Выделить всё
import requests
from bs4 import BeautifulSoup
url = 'https://www.detik.com/search/searchall?query=KPK'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
artikel = soup.findAll('div', {'class' : 'list media_rows list-berita'})
p = 1
link = []
for p in artikel:
s = p.findAll('a', href=True)['href']
link.append(s)
Код: Выделить всё
TypeError Traceback (most recent call last)
in
3 link = []
4 for p in artikel:
5 s = p.findAll('a', href=True)['href']
6 link.append(s)
TypeError: list indices must be integers or slices, not str
Подробнее здесь: https://stackoverflow.com/questions/680 ... utifulsoup
Мобильная версия