0

Problem: So, I wanted to get links from a search results on a wiki from a game, and got this error

Link from search resutls im trying to get to: Html.png

Error: li_tag = ul_tag.find('li') AttributeError: 'NoneType' object has no attribute 'find

Code:

    ul_tag = h2_tag.find('ul')
    li_tag = ul_tag.find('li')
    div_tag = li_tag.find('div')
    a_tag = div_tag.find('a')

    urls.append(a_tag.attrs['href'])
Alastair McCormack
  • 23,069
  • 7
  • 60
  • 87
TotoMC
  • 3
  • 2
  • One of your finds is not returning a result. The error message will contain a stacktrace which will point to which line and therefore which `find` is failing. – Alastair McCormack Nov 25 '20 at 13:41
  • Also, have a look at https://stackoverflow.com/questions/5041008/how-to-find-elements-by-class. This should allow you to quickly find all elements using `mw-redirect` class – Alastair McCormack Nov 25 '20 at 13:44
  • So, the problem was that the ul tag wasn't inside the h2 tag, but now I the program can't find the a tag inside the div, and by the screenshot I posted with the question, there should be one inside it, right? @AlastairMcCormack (just saw your second comment, I'll try that too) – TotoMC Nov 25 '20 at 13:47
  • Remember that you're looking at the DOM, not the source code. Any Javascript on the page can add new entries to the DOM. BS only reads the source code. Check the source code contains the information you're looking for. Also consider my previous point about searching for the class or classes. – Alastair McCormack Nov 25 '20 at 13:52
  • Ok, thanks Alastair – TotoMC Nov 25 '20 at 14:23

1 Answers1

0

Your h2_tag.find('ul') not found anything so it returns None. h2 tag is not including ul and li, h2 tag opened and closed. Try searching XML and see some examples that will help you so much.

AriaN
  • 143
  • 6