+ 1
how to combine 100 list into one
i have 100 list, now i want to combine them into one. i know use list1+list2....,but this make me crazy. so is there any convenient way to make the job easier?
5 Réponses
+ 4
The question is: Where do these 100 lists come from? Are they stored in an external file? Or are they all defined in a python file?
+ 1
Lothar i crawl a website and using the following code:for i in range(100):
url_i = 'http://www.haoshiwen.org/search.php?author=%E6%9D%8E%E7%99%BD&page=' + \
str(i)
headers = {'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36'}
r1 = requests.get(url=url_i, headers=headers)
source = r1.content
soup = BeautifulSoup(source, features='lxml')
poems_link = soup.find_all('p')[0]
# print(poems_link)
poemLinks = []
for poem in poems_link:
print(poem['href'])
# try:
# poemLinks.append('http://www.haoshiwen.org/' + poem['href'])
# except BaseException:
# pass
# print(poemLinks)
+ 1
when i run print(poemlinks ) ,which i hope to get a poemlinks list,but the output is 100 separated list.