1
我想把刮網址保存到文本文件,但是我在文件中找到的結果與打印的結果不同。我只能找到文件中的最後一組。Python寫網址到BeautifulSoup的文件
urls = ["http://google.com/page=","http://yahoo.com"]
for url in urls:
for number in range(1,10):
conn = urllib2.urlopen(url+str(number))
html = conn.read()
soup = BeautifulSoup(html)
links = soup.find_all('a')
file= open("file.txt","w")
for tag in links:
link = tag.get('href')
print>>file, link
print link
file.close()