我正在尝试抓取 Twitter 以获得一些结果,但它使我陷入错误
import requests
import re
from bs4 import BeautifulSoup
url = u'https://twitter.com/search?q='
query = u'q=cruise&src=typed_query'
r = requests.get(url+query)
soup = BeautifulSoup(r.text,'html.parser')
tweets = []
for item in soup.findAll('span',attrs={"class":"css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0"}):
result = [item.get_text(strip=True, separator=" ")]
tweets.append(result.text.encode("utf-8"))
f = open('search.csv', 'w')
f.write(r.text)
当我尝试打印(推文)时,它给了我一个空列表,对于 f.write(r.text) 它给了我以下错误
'charmap' codec can't encode character '\U0001f602' in position 17391: character maps to <undefined>