i only want to scrap username from a webpage , the username change everytime i loged in
here is the code
</tr><tr><td>Phone Number:</td><td>(701) 684-1390</td></tr><tr><td>Username:</td><td>**Username here**</td></tr>
So how can i only grab the username by using regex ?
Use BeautifulSoup
parser.
import urllib
from bs4 import BeautifulSoup
HTML_Text = '''</tr><tr><td>Phone Number:</td><td>(701) 684-1390</td></tr><tr><td>Username:</td><td>Username here</td></tr>'''
soup = BeautifulSoup(HTML_Text, 'html.parser')
td = soup.select('td')
for i,j in enumerate(td):
if j.text == 'Username:':
print td[i+1].text
break
Output:
Username here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.