python、Web垃圾处理和编写文件

python、Web垃圾处理和编写文件,python,request,urllib,Python,Request,Urllib,我在这个程序中使用了3个模块,我不知道我想做的是否可能!所以我想从twitter上刮取一些数据,并用python将其写入一个文本文件,有人能告诉我,为什么我的代码没有将这些数据刮去 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 = "ht

我在这个程序中使用了3个模块,我不知道我想做的是否可能!所以我想从twitter上刮取一些数据,并用python将其写入一个文本文件,有人能告诉我,为什么我的代码没有将这些数据刮去

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!!")

你只是在写你收到的文件的标题

        f.write(soup.title.text)

你不应该从他们那里收集数据,也不应该使用像

im这样的库。我不是完全废弃twitter,我只是想弄清楚如何将标题放在文本文档中,所有这些都是用python代码编写的。我不明白你的反应,我的代码里有。是在错误的地方吗?我指的是你只是在写标题。删除他们网站的任何部分都是违反ToS的。当你运行这个代码时,你会遇到什么错误?哦,我不知道我应该从我的comp中删除代码吗?