-2
我想我想变成一个列表是一个字符串。将字符串转换成列表
所以当我运行它打印出一个网址列表。我希望把这些网址到像这样的列表:
["Apple", "Pear", "Radio"]
代码:
url = "http://www.wired.com/category/science/page/"
a = list(range(1, 12))
i=0
while i < len(a):
urls1 = url + str(i)
print urls1[1]
i+=1
我想要做的:(我想,如果我结合他们两个,我可以得到网址去与刮刀)
import urllib
import re
urls = [urls1]
#https://www.wired.com/2016/07/google-tests-new-crypto-chrome-fend-off-quantum-attacks/
i=0
regex = '<h2 class="title brandon clamp-5">(.+?)</h2>'
#https?:(\/\/www\.wired\.com\/2016(\/[A-Za-z0-9\-\._~:\/\?#\[\]@!$&'\(\)\*\+,;\=]*)?)
pattern = re.compile(regex)
while i < len(urls):
htmlfile = urllib.urlopen(urls[i])
htmltext = htmlfile.read()
titles = re.findall(pattern, htmltext)
for elem in titles:
print elem
i+=1
所以你想要一个网址列表?网址从哪里来?什么是'urls1'? –
@MoonCheesez我最初想到的是将两者结合起来,这就是为什么urls1处于最底层的原因。这些网址最初在一个列表中。 – user5544792
@MoonCheesez我想制作一个网址列表,然后在这个网址中使用这些网址 – user5544792