【问题标题】:Can't parse twitter hidden input with BeautifulSoup无法使用 BeautifulSoup 解析 twitter 隐藏输入
【发布时间】:2016-04-02 10:43:44
【问题描述】:

我正在尝试检索推文计数。我发现用户推文的实际数量在隐藏字段中。

其中,我正在使用 BeautifulSoup 进行解析:

def get_twitter(url):
  soup = BeautifulSoup(urllib2.urlopen(url))
  for match in soup.find_all("input", type="hidden"):
    print match

结果: [2

正如您所见,在浏览器的屏幕截图中没有隐藏的输入字段。为什么会这样?

【问题讨论】:

  • 你为什么不直接使用twitter API?谢谢。
  • 它可能是由 JavaScript 添加的,它不会通过 python 或任何其他语言从原始数据连接呈现

标签: python python-2.7 parsing twitter beautifulsoup


【解决方案1】:

解决了。使用推特 API。不知何故认为解析会更容易。感谢alecxe的建议。

import simplejson
from twython import Twython

def get_twitter():
    t = Twython(app_key='', 
    app_secret='',
    oauth_token='',
    oauth_token_secret='')

    user = t.lookup_user(screen_name = username)
    print "Tweets: " + str(user[0]['statuses_count'])
    print "Followers: " + str(user[0]['followers_count'])
    print "Likes: " + str(user[0]['favourites_count'])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 2019-04-13
    • 1970-01-01
    • 2018-10-26
    相关资源
    最近更新 更多