Issue
import requests
from user_agent import generate_user_agent
url = "https://myweb.com/myapi/test"
headers = {f'User-Agent': generate_user_agent()}
while True:
response = requests.get(url, headers=headers, verify=False)
print(response.text)
i want no restart , loop random ua for every request new ua string
They test this code giving 1 one same ua and looping work but i need change ua for "every" request
new useragent = need reboot restart code but i dont want restart code, directly loop, (loop working but same ua) i want get random ua for every every req reget without restart sry for my eng
Solution
You're only computing headers
once outside the loop, so of course the user agent won't change. Move it inside the loop.
import requests
from user_agent import generate_user_agent
url = "https://myweb.com/myapi/test"
while True:
headers = {"User-Agent": generate_user_agent()}
response = requests.get(url, headers=headers, verify=False)
response.raise_for_status()
print(response.text)
Answered By - AKX
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.