你好我想颳了最新的電影www.allocine.fr初學者不知道如何加入名單,而刮
我做了下面的腳本:
# -*- coding: utf-8 -*-
import urllib
import re
page = ["?page=1", "?page=2", "?page=3"]
i=0
while i<len(page):
url = "http://www.allocine.fr/film/aucinema/" +page[i]
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex = '<a class="no_underline" href="/film/fichefilm_gen_cfilm=[^.]*.html">\n(.+?)\n</a>'
pattern = re.compile(regex)
movie = re.findall(pattern,htmltext)
i+=1
movielist = '\n '.join(movie)
print movielist
的問題是,第一併且列表中的最後一項在它們前面沒有空格...我想說的是輸出中第一個列表中的最後一個項目和第二個列表中的第一個項目不由空格分隔。
它看起來像這樣:
Something in 1st list
something2 in 1st list
something3 in 1st list
Otherthing in 2nd list
otherthing2 in 2nd list
otherthing3 in 2nd list
====
我想這是這樣的: 東西 東西 東西 otherthing otherthing
另外對於網絡報廢,你可能想看看[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/bs4/doc/) – bvidal 2014-09-02 14:56:01
只需添加它:'movielist =''+ movielist' – Germano 2014-09-02 14:58:35