使用 Python 获取 Twitter 新闻源
大家好,我最近一直在使用 Python 2.7 和 BeautifulSoup 3.2,我已经得到了适用于 Facebook 的代码,它向 Facebook 发出 POST 请求以登录并将 HTML 下载到页面,然后将其保存到我的电脑。我尝试用 Twitter 执行此操作,但它似乎不起作用*.. 这是我的代码:
import urllib, urllib2
from BeautifulSoup import BeautifulSoup
#I've replaced my actual username and password for obvious reasons
form = urllib.urlencode({'username':'myUsername','password':'myPassword'})
response = urllib2.urlopen('https://mobile.twitter.com/session',form)
response = response.read()
谁能告诉我它出了什么问题?谢谢!
*在我执行response = response.read()之后,我将其写入硬盘上的文件并用firefox打开它。当我打开它时,我看到的只是当时 http://mobile.twitter.com/ 上的内容我运行脚本。
Hey everybody, I've been playing around with Python 2.7 and BeautifulSoup 3.2 recently and I've gotten my code to work for Facebook where it makes a POST request to Facebook to login and downloads the HTML to the page, then saves it to my computer. I tried doing this with Twitter but it doesn't seem to be working*.. here's my code:
import urllib, urllib2
from BeautifulSoup import BeautifulSoup
#I've replaced my actual username and password for obvious reasons
form = urllib.urlencode({'username':'myUsername','password':'myPassword'})
response = urllib2.urlopen('https://mobile.twitter.com/session',form)
response = response.read()
Can anyone tell me what's wrong with it? Thanks!
*After I do response = response.read() I have it write to a file on my harddrive and open it with firefox. When I open it all I see is whatever is on http://mobile.twitter.com/ at the time of me running the script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要查看Python 的 Twitter 库。
You may want to check out the Twitter libraries for Python.