Python wget saves a file. how to get data in variable
我在python中使用wget作为
1 2 3 4 5 6 | import wget from bs4 import BeautifulSoup url ="https://www.facebook.com/hellomeets/events" down = wget.download(url) print down |
它将HTML数据下载到一个文件中。但我希望它在变量上。我是Python的新手。任何帮助都将不胜感激。提前谢谢
您不需要使用
1 2 3 4 5 6 | import requests from bs4 import BeautifulSoup url ="https://www.facebook.com/hellomeets/events" html = requests.get(url).text print html |
这是一个使用
1 2 3 4 5 6 | import urllib2 from bs4 import BeautifulSoup url ="https://www.facebook.com/hellomeets/events" html = urllib2.urlopen(url).read() print html |
号编辑
我知道你所说的直接从网站获取的HTML和从
1 2 3 4 5 6 7 8 9 10 11 | import wget from bs4 import BeautifulSoup url ="https://www.facebook.com/hellomeets/events" down = wget.download(url) f = open(down, 'r') htmlText =" ".join(f.readlines()) f.close() print htmlText |