首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python twint库无法在Colab环境中工作。

Python twint库无法在Colab环境中工作。
EN

Stack Overflow用户
提问于 2021-04-22 17:33:14
回答 3查看 4.1K关注 0票数 2

我试图在Colab中使用Python的twint库(Twitter刮刀)运行一段代码。

我的代码是:

代码语言:javascript
复制
!pip install twint
!pip install nest_asyncio
!pip install pandas

import twint
import nest_asyncio
nest_asyncio.apply()
import time
import pandas as pd
import os
import re

timestr = time.strftime("%Y%m%d")

c = twint.Config()
c.Limit = 1000
c.Lang = "en"
c.Store_csv = True
c.Search = "apple"
c.Output = timestr + "_en_apple.csv"
twint.run.Search(c)

上面的代码在我的机器上运行得很好,可以在我的机器上运行,并获取tweet。然而,Colab中的相同代码产生了以下结果:

代码语言:javascript
复制
 CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
 sleeping for 1.0 secs
 CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
 sleeping for 8.0 secs
 CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
 sleeping for 27.0 secs
 CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
 sleeping for 64.0 secs
 CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
 sleeping for 125.0 secs
 CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
 sleeping for 216.0 secs

怎么才能在科拉布修好呢?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-04-23 07:46:26

我有以下工作在谷歌科拉布。从requirements.txt安装较少麻烦。

代码语言:javascript
复制
!git clone --depth=1 https://github.com/twintproject/twint.git
!cd /content/twint && pip3 install . -r requirements.txt
import twint
import nest_asyncio
nest_asyncio.apply()
import time
import pandas as pd
import os
import re
timestr = time.strftime("%Y%m%d")

c = twint.Config()
c.Limit = 1000
c.Lang = "en"
c.Store_csv = True
c.Search = "apple"
c.Output = timestr + "_en_apple.csv"
twint.run.Search(c)
票数 4
EN

Stack Overflow用户

发布于 2021-12-18 16:52:51

对于那些失败的构建,编辑您的requirements.txt像这样;

代码语言:javascript
复制
aiohttp==3.7.0
aiogram==2.2
aiodns
beautifulsoup4
cchardet
dataclasses
elasticsearch
pysocks
pandas>=0.23.0
aiohttp_socks<=0.4.1
schedule
geopy
fake-useragent
googletransx
票数 0
EN

Stack Overflow用户

发布于 2022-09-16 22:06:00

这是在google上运行的更新代码。

代码语言:javascript
复制
!git clone --depth=1 https://github.com/twintproject/twint.git
!cd /content/twint && pip3 install . -r requirements.txt
!pip install aiohttp==3.7.0
!pip install nest_asyncio
# Import Libraries
import twint
import nest_asyncio
nest_asyncio.apply()
import time
import pandas as pd
import os
import re
timestr = time.strftime("%Y%m%d")
#configuration
c = twint.Config()   
c.Limit = 1000       
c.Lang = "en"        # Language
c.Store_csv = True
c.Search = "robin i love you"  # key words to look for.
c.Output = timestr + "_en_robin.csv"
twint.run.Search(c)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67218168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档