(蟒蛇2.7.4)
我只想打印我称之为 url 的内容,如果它包含“watch”这个词,我已经进行了一些试验和错误,但无济于事。另外我想知道是否可以捕获每个视频的名称(来自 html)并将其分配给相应的视频,任何帮助或指针将不胜感激。
我使用的链接是' http://thenewboston.org/list.php?cat=36 '
import urllib2
import re
def OPEN_URL(url):
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
response = urllib2.urlopen(req)
link=response.read()
response.close()
return link
link=OPEN_URL('http://thenewboston.org/list.php?cat=36')
match=re.compile('href="(.+?)"').findall(link)
for url in match:
url='http://thenewboston.org/'+url
print url