Marvel
Marvel

Reputation: 29

get a value of string with beautiful soup using python

I've made a script that extracts texts from forum website, there's no problem with it but I want to get a value of the string which user posted, for example, see below

s = "(Username[^\"]+)(?:<div>)"
r = requests.get("https://example.com/threads/73956/page2", headers=headers, cookies=cookies)
soup = BeautifulSoup(r.content, "html.parser")
result = re.findall(s, r.text)
print(result[0].replace("<br />", ""))

I want the value of string number which is 2

<div class="wwCommentBody">
     <blockquote class="postcontent restore " style="padding: 10px;">Username: 
     leetibrahim<br>
    Number: 2       
     </blockquote>
</div>

Upvotes: 0

Views: 51

Answers (1)

A.M. Ducu
A.M. Ducu

Reputation: 900

This regex should yield the number string:

n_str = r"(?<=Number:)(.+)"
r = requests.get("https://ffs.gg/threads/73956/page2", headers=headers, cookies=cookies)
soup = BeautifulSoup(r.content, "html.parser")
result = re.findall(n_str, r.text)
print(result[0])

Upvotes: 1

Related Questions