0

Im trying to change my user-agent using the code below. But it gets recognized as "python-requests/2.22.0"

from lxml import html import requests headers = { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } page = requests.get('http://www.useragentstring.com/') tree = html.fromstring(page.content) userAgent = tree.xpath('//*[@id="uas_textfeld"]/text()') print(userAgent[0]) 

1 Answer 1

1

In your header,you even didn't add it to your request.

page = requests.get('http://www.useragentstring.com/',headers=headers) 

Now it show me the right user-agent: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.