Python Forum
Don't know what went wrong - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Don't know what went wrong (/thread-27823.html)



Don't know what went wrong - Tejas - Jun-23-2020

I was trying to make a webcrawler to get the years only of a specific page only as practice but it failed
seems fine to me but not have any idea what is wrong

import requests
from bs4 import BeautifulSoup

def search_year (page_number):
    url = "https://b-ok.asia/s/Python?page=" + str(page_number)
    source_code = requests.get(url)
    plain_text = source_code.text
    soup = BeautifulSoup(plain_text)
    for link in soup.findAll("div" , {"class" : "property_value"}):
        year = link.string
    print (year)

search_year(1)



RE: Don't know what went wrong - nuffink - Jun-23-2020

Hello.

When you say it failed, that could be because there is a "Y" in the day (Tuesday).....no seriously without any tracestack or even wording from yourself no-one on here will have the mental telepathy to guess what has gone wrong, please try to supply the following with as much information as possible, your environment, your IDE (if using one), the python version you are using, how the error manifests itself or are you just basing it on the fact it didn't return any results, it could be security on the site you are crawling, the possibilities are endless :) - basically supply all the details that will allow members to make an informed suggestion to your problem.

Some things you can check for yourself like :-
  • Am i sure the methods i am calling are correct and of the correct case?
  • If I change my find all to something more simplistic does it return me anything at all - use the print function to display your variable etc
Thanks