0

I tried to create my first python web crawler (learned it from thenewboston). I dont get any error messages, but also no output.. Heres my code:

import requests
from bs4 import BeautifulSoup

def sportpoint_spider(max_pages):
    page = 1
    while page <= max_pages:
        url = 'http://www.sportpoint.lt/vyrams-1?page=' + str(page)
        source_code = requests.get(url)
        plain_text = source_code.text
        soup = BeautifulSoup(plain_text, "html.parser")
        for link in soup.findAll('a', {'atl '}):
            href = link.get('href')
            print(href)
        page += 1

sportpoint_spider(1)
7
  • Could you add print(plain_text) statement after plain_text = source_code.text and post results? Commented Oct 15, 2017 at 18:20
  • it printed all website text, classes and etc. (all text from inspect element) Commented Oct 15, 2017 at 18:24
  • What is the desired output? Commented Oct 15, 2017 at 18:25
  • Process finished with exit code 0 Commented Oct 15, 2017 at 18:26
  • Isn't that what its supposed to do? It runs and then exits. You need to save the output to a file. Commented Oct 15, 2017 at 18:29

1 Answer 1

2

Your problems lays at this line

for link in soup.findAll('a', {'atl '}):

according to docs second argument attrs should be a dictionary with pairs like {'attr_name': 'attr_value'}. And {'atl '} is a set. Also, I think you mean 'alt', not 'atl'. Try to use

for link in soup.findAll('a'):

There aren't 'a' elements on page with attribute 'alt'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.