-2

I am trying to count how many times an string "Airport" appears on an website. I tried to use Request Module , BS4 etc. and tried to scrap data from there, but the REST response returns a very concise xml which actually does not contain the text in it. Find_Element_By_Link_Text method also does not work here as the string "Airport" is part of the texts shown on the page. Is there any method that I can use to count the number of occurrences of the text "Airport" on the page?

martineau
  • 112,593
  • 23
  • 157
  • 280
nhrcpt
  • 842
  • 2
  • 18
  • 46

2 Answers2

2

You can use browser.page_source, convert it to a string and use regular expression findall.

Python Selenium accessing HTML source

Python regex findall

nicholas.reichel
  • 2,190
  • 6
  • 17
  • 27
-1

why don't you use some javascript?

get all the html code/text

var wholeText = document.documentElement.innerHTML;

then split by "Airport"

var repeat = wholeText.split("Airport");

finally count the elements in your repeat array

total = repeat.length -1 

this should give you all the airports in the whole code (including backend)

another easy approach is just use your Ctrl + F and find the occurrences manually

Developer Guy
  • 2,198
  • 6
  • 18
  • 34
Mike
  • 749
  • 8
  • 15