Skip to content
Advertisement

Web scraping a text() in python

I am having trouble with a web scraping function. The XPath for the two things I am trying to get are

JavaScript

The html is

JavaScript

I am trying to have a function to loop through each li in tr[5]. The problem I am having is getting the text(). I have tried a number of different variations of this function

JavaScript

This specific function returns an KeyError on the ‘()’. If I remove (), it returns a list of empty elements. The lnk_txt works.

What I am trying to get are two list. One is the name of the University. The other is the location of the University. The ultimate goal is to make tuples (name, state).

Advertisement

Answer

You need to find the following text sibling of the a element:

JavaScript

Demo:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement