Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some help with parsing
#9
(Jan-20-2020, 12:48 PM)jkessous Wrote: How do i get both on the same line that it will be something like this

name - id
There is own id tag in card that get eg id="989670".
import requests
from bs4 import BeautifulSoup

url = 'https://connectedinvestors.com/member/jonathan-kessous/friends/2'
url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'html.parser')
for tag in soup.find_all('div', class_="investorcard clearfix"):
    h4 = tag.find('h4')
    print(h4.a.text.strip(), tag.attrs['id'])
Output:
Jonathan Kessous 454517 Diunique Williams 950184 Aundre Price 989670 Larry Jackson 265408 Josie Djach 577911 .....ect
Let say want to take user id from.
Output:
/uploads/user/252881/img_552a543595cab.jpg
Here do the parser stop working as it's just text output,so can eg use regex.
>>> import re
>>> 
>>> s = '/uploads/user/252881/img_552a543595cab.jpg'
>>> re.search( r"user/(\d+)", s).group(1)
'252881'
Reply


Messages In This Thread
Need some help with parsing - by jkessous - Jan-19-2020, 07:34 PM
RE: Need some help with parsing - by Axel_Erfurt - Jan-19-2020, 08:40 PM
RE: Need some help with parsing - by snippsat - Jan-19-2020, 09:37 PM
RE: Need some help with parsing - by jkessous - Jan-19-2020, 09:45 PM
RE: Need some help with parsing - by snippsat - Jan-19-2020, 10:04 PM
RE: Need some help with parsing - by jkessous - Jan-19-2020, 10:51 PM
RE: Need some help with parsing - by snippsat - Jan-20-2020, 12:44 AM
RE: Need some help with parsing - by jkessous - Jan-20-2020, 12:48 PM
RE: Need some help with parsing - by snippsat - Jan-20-2020, 06:12 PM
RE: Need some help with parsing - by jkessous - Jan-20-2020, 06:40 PM
RE: Need some help with parsing - by snippsat - Jan-21-2020, 12:18 AM
RE: Need some help with parsing - by jkessous - Jan-21-2020, 05:48 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020