How to fix a TypeError: bad operand type for unary +: 'str'?

import requests, bs4
from datetime import datetime

now = (datetime.now())

r = datetime.strftime(datetime.now(), "%Y-%m-%d") # get the current date in the form spiska



url = ('https://sinoptik.com.ru/погода-горловка#',+ r)




print(url)



for r in s:
s=requests.get(url)

 b=bs4.BeautifulSoup(s.text, "html.parser")

 p3=b.select('.temperature .p3')
pogoda1=p3[0].getText()

 p4=b.select('.temperature .p4')
pogoda2=p4[0].getText()

 p5=b.select('.temperature .p5')
pogoda3=p5[0].getText()

 p6=b.select('.temperature .p6')
pogoda4=p6[0].getText()

 print('Am :' + pogoda1 + '' + pogoda2)
 print('Day :' + pogoda3 + '' + pogoda4)

 p=b.select('.rSide .description')
pogoda=p[0].getText()

 print(pogoda.strip())


and here is the error:

Traceback (most recent call last):
File "weather.py", line 19, in
url = ('https://sinoptik.com.ru/погода-горловка#',+ r)
TypeError: bad operand type for unary +: 'str'

***Repl Closed***

what type do I need to do row r , but that in the future I could change it the last element
June 7th 19 at 14:50
2 answers
June 7th 19 at 14:52
Solution
A comma before the plus clean. However, you can remove all the sequence of characters #', + r, as part of the url after the # symbol is still in the requests are not transmitted.
import requests, bs4
from datetime import datetime

now = (datetime.now())

r = datetime.strftime(datetime.now(), "%Y-%m-%d") # get the current date in the form spiska


print('tekuma date:', r)


url = ('https://sinoptik.com.ru/погода-горловка#'+ r)


g = str(now.day)





for r in url:
 s=requests.get('https://sinoptik.com.ru/погода-горловка#'+ r)

 b=bs4.BeautifulSoup(s.text, "html.parser")
 p3=b.select('.temperature .p3')
pogoda1=p3[0].getText()

 p4=b.select('.temperature .p4')
pogoda2=p4[0].getText()
 p5=b.select('.temperature .p5')
pogoda3=p5[0].getText()
 p6=b.select('.temperature .p6')
pogoda4=p6[0].getText()

 print('Am :' + pogoda1 + '' + pogoda2)
 print('Day :' + pogoda3 + '' + pogoda4)
 p=b.select('.rSide .description')
pogoda=p[0].getText()
print(pogoda.strip())

 g += 1



 r.insert( -1 , g)


what he doesn't like? I want 1 item increase for 1 - amos_Sawayn73 commented on June 7th 19 at 14:55
it is important to me that after the #data,

https://sinoptik.com.ru/погода-москва - the weather today

https://sinoptik.com.ru/погода-москва#2018-03-03 - the weather tomorrow - amos_Sawayn73 commented on June 7th 19 at 14:58
, r[-1] += 1 - samir39 commented on June 7th 19 at 15:01
server sinoptik.com.ru always gives a page that contains a 7 day forecast, regardless of what you tell him after the # symbol will give. Date after the # symbol only uses javascript this page running in the browser. That's just not BeautifulSoup browser and javascript will not perform. - samir39 commented on June 7th 19 at 15:04
still the same error
r[-1] += 1
TypeError: must be str, not int - amos_Sawayn73 commented on June 7th 19 at 15:07
of course, there you have the same string. - samir39 commented on June 7th 19 at 15:10
June 7th 19 at 14:54
Remove the comma in that string which comes after the URL.
Here it is:
url = ('https://sinoptik.com.ru/погода-горловка#' + r)
import requests, bs4
from datetime import datetime

now = (datetime.now())

r = datetime.strftime(datetime.now(), "%Y-%m-%d") # get the current date in the form spiska


print('tekuma date:', r)


url = ('https://sinoptik.com.ru/погода-горловка#'+ r)


g = str(now.day)





for r in url:
 s=requests.get('https://sinoptik.com.ru/погода-горловка#'+ r)

 b=bs4.BeautifulSoup(s.text, "html.parser")
 p3=b.select('.temperature .p3')
pogoda1=p3[0].getText()

 p4=b.select('.temperature .p4')
pogoda2=p4[0].getText()
 p5=b.select('.temperature .p5')
pogoda3=p5[0].getText()
 p6=b.select('.temperature .p6')
pogoda4=p6[0].getText()

 print('Am :' + pogoda1 + '' + pogoda2)
 print('Day :' + pogoda3 + '' + pogoda4)
 p=b.select('.rSide .description')
pogoda=p[0].getText()
print(pogoda.strip())

 g += 1



 r.insert( -1 , g)


what he doesn't like? I want 1 item increase for 1 - amos_Sawayn73 commented on June 7th 19 at 14:57

Find more questions by tags Python