-1
私はこのプログラムで3つのモジュールを使用していますが、私がしようとしていることが可能であるかどうかはわかりません!だから、私はTwitterのデータを掻き集めて、Pythonを使ってテキストファイルに書きたいのですが、誰かが私を案内して、私のコードがデータを書き込んでいない理由を教えてください。python、webscraping、およびファイルを書く
import urllib
import urllib.request
from os import path
from bs4 import BeautifulSoup
# here I define the url, I request the page, create my soup
theurl = "https://twitter.com/realDonaldTrump"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage, "html.parser")
def create_file(dest):
"""
Creates a file for the user to write data in!
:param dest:
:return:
"""
## FileName == Month_Day_Year
name = 'Data Scraped.txt'
if not(path.isfile(dest +name)):
f = open(dest + name, "w")
f.write(soup.title.text)
f.close()
if __name__ == '__main__':
destination = 'C:\\Users\\edwin\\' \
'Desktop\\WebScrappin\\'
create_file(destination)
print("Your file has been created!!")
イムは完全にさえずりをスクラップないようにライブラリを使用する必要があります(against their ToSである)こするの
、イムはちょうどにタイトルを配置する方法を把握しようテキスト文書は、すべて私のPythonコードで書かれています。私はURの応答を理解していない、私は自分のコードでそれを持っています。それは間違った場所にありますか? –
私はあなたがタイトルだけを書いていると言います。サイトの一部を削ることは、ToSには反対です。 – Alex
このコードを実行すると、どのようなエラーが発生しますか? – Alex