Reputation: 165
I am new to Python and making use of requests in python . I am asked to do loggin on xyz.com which i am able to do . And extract all the Table contents which are link to discussion . in each of these link i need to find the occurence of "The" word . how should i proceed ?My code is given below
tags=content2.findAll("td",{'class':'topic starter'})
for i in tags:
thread_link=i.find('a').get('href')
print(thread_link)
result3=session.post(thread_link)
content3=bs4.Beautifulsoup(result3.text,'html.parser')
tag3=content3.find("the",count+1)
print(count)
I have to find the occurence of the in each link and print it!!
Upvotes: 1
Views: 74
Reputation: 14689
You can use str.count, check here for more details
for i in tags:
thread_link=i.find('a').get('href')
result3=session.post(thread_link)
count = result3.text.count("the")
print(count)
Upvotes: 3
Reputation: 1375
You are not doing this correctly. Your tag3 will be finding the
tag. Also code is little messy. You can use regex
for your cause. Here we will search for the
in the result text.
import re
for i in tags:
thread_link=i.find('a').get('href')
print(thread_link)
result3=session.post(thread_link)
count=len(re.findall('\sthe\s',result3.text))
print(count)
Upvotes: 1