How can I scrape code inside div with BeautifulSoup?

烂漫一生 提交于 2021-01-29 19:39:25

问题


I am having problems scraping code inside div not between them, with BeautifulSoup and python. Below I wrote a html code what I want to scrap (data-friendscount , data-followerscount Values)

<div data-profileuserid="285904056" data-friendscount="100" data-followerscount="7102" data-followingscount="25" data-arefriends="false" class="hidden ng-isolate-scope"></div>

回答1:


toc = requests.get(f'roblox.com/users/75790059/profile')
soup = BeautifulSoup(toc.content, 'html.parser')
divs = soup.find_all("div", class_="hidden ng-isolate-scope")
for div in divs:
    print(div.attrs.get('data-profileuserid', None))
    print(div.attrs.get('data-friendscount', None))
    print(div.attrs.get('data-followerscount', None))
    print(div.attrs.get('data-followingscount', None))
    print(div.attrs.get('data-arefriends', None))


来源:https://stackoverflow.com/questions/60736787/how-can-i-scrape-code-inside-div-with-beautifulsoup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!