日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 多数据输出到txt_python-BeautifulSoup输出到.txt文件

發(fā)布時間:2024/1/23 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 多数据输出到txt_python-BeautifulSoup输出到.txt文件 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我正在嘗試將數(shù)據(jù)導(dǎo)出為.txt文件

from bs4 import BeautifulSoup

import requests

import os

import os

os.getcwd()

'/home/folder'

os.mkdir("Probeersel6")

os.chdir("Probeersel6")

os.getcwd()

'/home/Desktop/folder'

os.mkdir("img") #now `folder`

url = "http://nos.nl/artikel/2093082-steeds-meer-nekklachten-bij-kinderen-door-gebruik-tablets.html"

r = requests.get(url)

soup = BeautifulSoup(r.content)

data = soup.find_all("article", {"class": "article"})

with open(""%s".txt", "wb" %(url)) as file:

for item in data:

print item.contents[0].find_all("time", {"datetime": "2016-03-16T09:50:30+0100"})[0].text

print item.contents[0].find_all("a", {"class": "link-grey"})[0].text

print "

"

print item.contents[0].find_all("img", {"class": "media-full"})[0]

print "

"

print item.contents[1].find_all("div", {"class": "article_textwrap"})[0].text

file.write()

應(yīng)該放在:

file.write()

上班?

我還試圖將.txt文件的名稱與url相同,應(yīng)該使用字符串嗎?

with open(""%s".txt", "wb" %(url)) as file:

url = "http://nos.nl/artikel/2093082-steeds-meer-nekklachten-bij-kinderen-door-gebruik-tablets.html"

總結(jié)

以上是生活随笔為你收集整理的python 多数据输出到txt_python-BeautifulSoup输出到.txt文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。