I am new to programming and also new to pyhon.
My intension is to built an ebay webscraper.
I am trying to extract an list of links with the bs4 find_all() method, but no matter what I try, it returns always an empty list.
def get_index_data(soup):
try:
links = soup.find_all('a', {'class': 's-item__link'})
print(links)
except:
links = []
print(links)
I wrote it also that way.
links = soup.find_all('a', class_= 's-item__link')
It also returns an empty list. I absolutely don´t know what is wrong
Edit:
import requests
from bs4 import BeautifulSoup
def get_page(url):
response = requests.get(url)
if not response.ok:
print('server responded: ', response.status_code)
else:
soup = BeautifulSoup(response.text, 'lxml')
return soup
def get_index_data(soup):
links = soup.find_all('a')
print(links)
def main():
url = 'https://www.ebay.de/sch/i.html?_nkw=armbanduhr&_pgn=1 '
get_index_data(get_page(url))
if __name__ == '__main__':
main()
Edit2
Error after I run the code with only .find_all('a')
Traceback (most recent call last):
File "C:\Users\Aleksandar\Desktop\My ebay scraper\test", line 29, in <module>
main()
File "C:\Users\Aleksandar\Desktop\My ebay scraper\test", line 25, in main
get_index_data(get_page(url))
File "C:\Users\Aleksandar\Desktop\My ebay scraper\test", line 19, in get_index_data
print(links)
File "C:\Users\Aleksandar\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2705' in position 28776: character maps to <undefined>