Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
helllppp
can some one please help me???
this is my code:
import requests
from bs4 import *
import random
def read(c):
    request=requests.Session()
    request.headers.update({'useragent':'Mozilla/5.0 (Android 7.0; Mobile; rv:62.0) Gecko/62.0 Firefox/62.0'})
    url=f'http://pytesmfamil.blogfa.com/post/{c}'
    res=request.get(url,allow_redirects=True)
    my_html=BeautifulSoup(res.text,'html.parser')
    all_p=my_html.find_all('p',{'class':None})
    print(all_p)
    a=(random.choice(all_p))
    print(a)
read(1)

when i run it...
<p>سبزی پلو</p>

how can I remove
<p>
and
</p>
???
(actually I dont care about meaning of that persians word)

What I have tried:

the type of a is
<class 'bs4.element.Tag'>

so... its not a string that let me remove a char:((

{My native language is not English, so I apologize for the grammatical errors and misspellings:((}
Posted
Comments
Richard MacCutchan 16-Jun-22 11:35am    
The output will always be raw HTML from the web page you are reading. You will need to create the code to remove unwanted tags.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900