Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python抓取Twitter页面?_Python_Twitter_Python 2.7 - Fatal编程技术网

如何使用Python抓取Twitter页面?

如何使用Python抓取Twitter页面?,python,twitter,python-2.7,Python,Twitter,Python 2.7,当我尝试使用以下代码爬网Twitter时: import urllib2 s = "https://mobile.twitter.com/bing/" html = urllib2.urlopen(s).read() print html 。。。我得到以下错误: Traceback (most recent call last): File "C:\Users\arpit\Downloads\Desktop\Wiki Code\final Crawler_wiki.py", line 14

当我尝试使用以下代码爬网Twitter时:

import urllib2
s = "https://mobile.twitter.com/bing/"
html = urllib2.urlopen(s).read()
print html
。。。我得到以下错误:

Traceback (most recent call last):
  File "C:\Users\arpit\Downloads\Desktop\Wiki Code\final Crawler_wiki.py", line 14, in <module>
    html = urllib2.urlopen(s).read()
  File "C:\Python27\lib\urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 400, in open
    response = self._open(req, data)
  File "C:\Python27\lib\urllib2.py", line 418, in _open
    '_open', req)
  File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 1215, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "C:\Python27\lib\urllib2.py", line 1177, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>
回溯(最近一次呼叫最后一次):
文件“C:\Users\arbit\Downloads\Desktop\Wiki Code\final Crawler\u Wiki.py”,第14行,在
html=urllib2.urlopen(s.read())
文件“C:\Python27\lib\urllib2.py”,第126行,在urlopen中
return\u opener.open(url、数据、超时)
文件“C:\Python27\lib\urllib2.py”,第400行,打开
响应=自身打开(请求,数据)
文件“C:\Python27\lib\urllib2.py”,第418行,处于打开状态
"开放",
文件“C:\Python27\lib\urllib2.py”,第378行,在调用链中
结果=func(*args)
文件“C:\Python27\lib\urllib2.py”,第1215行,https\u open
返回self.do_open(httplib.HTTPSConnection,req)
文件“C:\Python27\lib\urllib2.py”,第1177行,在do_open中
引发URL错误(err)
URL错误:

如果我将
mobile.twitter.com
替换为
twitter.com
,那么它可以工作,但我希望它可以与
mobile.twitter.com

一起工作。twitter站点可能正在寻找一个用户代理,而您在通过urllib api发出请求时没有设置该代理

您可能需要使用类似的东西来伪造您的用户代理


但我强烈建议您使用,它提供了许多简单而出色的数据处理方式

你为什么在移动推特网站上爬行?Twitter有一个文档丰富的API,它提供了一切,并且有很多Python客户端库,我也尝试过Python Twitter API和Twython。两者都给出了相同的错误代码。我在一个代理后面,我想这会造成麻烦。我还为twitter发布了一个新的q API。@ArpitAgarwal好吧,我会将此标记为解决了那些想用防火墙问题刮伤twitter手机的人。