I am working with grabbing the line that matches for the strings I am searching in a webpage. I tried some approach but it reads and displayed everything. Below is the partial snippet.
import requests
url = "https://bscscan.com/address/0x88c20beda907dbc60c56b71b102a133c1b29b053#code"
queries = ["Website", "Telegram", "Submitted"]
r = requests.get(url)
for q in queries:
q = q.lower()
if q in r.text.lower():
print(q, 'Found')
else:
print(q, 'Not Found')
Current Output:
website Found
telegram Found
submitted Found
Wanted Output:
Submitted Found - *Submitted for verification at BscScan.com on 2021-08-08
Website Found - *Website: www.shibuttinu.com
Telegram Found - *Telegram: https://t.me/Shibuttinu
2
Answers
requests
is returning an html page which you have to parse with an html parser. One problem is that your target outputs are stuck in the middle of a long string which, after parsing, you have to extract using some string manipulation.You can parse the html with either beautifulsoup with css selectors, or lxml with xpath:
First, using lxml:
With beautifulsoup:
Output, in either case:
You are only printing
q
. Which is you query. You want to print the requestr
In short, you should try:
print(q, 'Found', r)
Lastly, in this website you won’t find any result because the text you are looking for is not inside a Text tag. You probably want to filter your request looking for a div with
class="ace_line_group"
.