'How I can put result of the cycle or run code inside function?
My code:
import requests
from bs4 import BeautifulSoup
from pywebio.input import *
from pywebio.output import *
request = requests.get("https://news.google.com/topics/CAAqRggKIkBDQklTS2pvUVkyOTJhV1JmZEdWNGRGOXhkV1Z5ZVlJQkZRb0lMMjB2TURKcU56RVNDUzl0THpBeFkzQjVlU2dBUAE/sections/CAQqSggAKkYICiJAQ0JJU0tqb1FZMjkyYVdSZmRHVjRkRjl4ZFdWeWVZSUJGUW9JTDIwdk1ESnFOekVTQ1M5dEx6QXhZM0I1ZVNnQVAB?hl=en-US&gl=US&ceid=US%3Aen")
content = BeautifulSoup(request.content, 'html.parser')
find = content.find('div', class_='ajwQHc BL5WZb')
#open('test.html', 'w').write(findstr.find)
h3 = find.find_all('h3')
time = find.find_all('time')
link = find.find_all('article')#.find_all('a').get('href').replace('.', '')
result = []
#print('https://news.google.com' + link)
put_html('<table border="1" width="100%" cellpadding="5">')
h3 = find.find_all('h3')
textoutput = []
for text in h3:
a1 = text.text
textoutput.append(a1)
for result in link:
alinks = result.find_all('a')
alinks1 = []
for alinks1 in alinks:
alinks2 = alinks1.get('href')
alinksreplace = str(alinks2)
alinksreplace1 = alinksreplace.replace(".", "")
alinksreplace2 = alinksreplace1.replace("None", "")
if (alinksreplace2 != ''):
if "publications" not in alinksreplace2:
a = "https://news.google.com" + alinksreplace2
put_html('<tr>\
<th><a href=' + a + '>' + textoutput[0:] + '</a><br /></th>\
<th>2</th>\
</tr>\
<tr>\
<td>3</td>\
<td>4</td>\
</tr>\
</table>')
I want this result:
<th><a href=' + a + '>' + for text in h3: text.text + '</a><br /></th>\
<th>2</th>\
or <th><a href=' + a + '>' + textoutput # print list
So I want run cycle in the put_html() function either print list in it. When I try print list I get TypeError: can only concatenate str (not "list") to str error. I tried a lot of different ways, but I can't escape cycle.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
