【问题标题】:scraping Tweet source labels of a tweet from twitter从推特上抓取推文的推文来源标签
【发布时间】:2019-11-05 10:07:14
【问题描述】:

我正在尝试抓取推文的推文来源标签。但我无法得到它。

import requests as req

url="https://twitter.com/AskPayPal/status/1191653088823635969"
html = req.get(url)
label = html.find('span',class_="css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0")

print(label.text)

输出应该是:Lithium Tech。

【问题讨论】:

  • 你标记了 beautifulsoup 但没有使用它soup.find('span',{'class':'classes'})

标签: python-3.x web-scraping beautifulsoup python-requests web-crawler


【解决方案1】:
import requests as req
from bs4 import BeautifulSoup
url="https://twitter.com/AskPayPal/status/1191653088823635969"
html = req.get(url)
soup = BeautifulSoup(html.text,'html.parser')
label = soup.find('span',{'class':"css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0"})
print(label.text)

这就是你要找的 :))

【讨论】:

  • 'NoneType' 对象没有属性 'text'。 lebel 变量没有得到任何东西。输出应该来自 Lithium Tech。
  • Label.getText()
猜你喜欢
  • 2018-07-28
  • 2011-08-27
  • 2013-02-22
  • 1970-01-01
  • 2022-11-24
  • 2022-09-27
  • 1970-01-01
  • 2020-08-24
  • 1970-01-01
相关资源
最近更新 更多