所以这是我正在运行的脚本,它可以在 Windows 中很好地输出,但在 ubuntu 中,它只是打印一个空列表
import urllib2
import os
import re
import csv
from bs4 import BeautifulSoup
useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17'
def main():
# lib-talkingpointsmemo.py
archive = 'http://talkingpointsmemo.com/archive.php'
getweeklinks(archive)
def getweeklinks(archivelink):
print 'something'
urls = []
request = urllib2.Request(archivelink, headers={'User-agent': useragent})
webpage = urllib2.urlopen(request).read()
soup = BeautifulSoup(webpage)
anchors = soup('a')
print anchors
for a in anchors:
print a['href']
if __name__ == '__main__' : main()
和输出:
something
[]
怎么了?我正在使用 Ubuntu 12.04.1 LTS