我试图从一些社交网络获取数据并放入mongodb。
这是html标签内的信息
<span class="ProfileNav-value" data-count="347235" data-is-compact="true">347K</span>
我能够按如下方式恢复347K
page = requests.get("https://twitter.com/cancaonova")
soup = BeautifulSoup(page.content, 'html.parser')
followers = soup.find_all(class_="ProfileNav-value")
seguidores = followers[2]
print seguidores.get_text()
但是我想在 data-cont 标记中获取数据我尝试这种方式,但结果是: none
page = requests.get("https://twitter.com/cancaonova")
soup = BeautifulSoup(page.content, 'html.parser')
followers = soup.find('data-count')
print(followers)
Tks for you
答案 0 :(得分:1)
使用'element.attrs'读取属性:
$req
答案 1 :(得分:0)
rel_soup = BeautifulSoup('<span class="ProfileNav-value" data-count="347235" data-is-compact="true">347K</span>','html.parser')
rel_soup.span['data-count']