随机生成user-agent函数

徘徊边缘 提交于 2019-12-02 12:54:13

import random

def get_ua():
first_num = random.randint(55, 62)
third_num = random.randint(0, 3200)
fourth_num = random.randint(0, 140)
os_type = [
‘(Windows NT 6.1; WOW64)’, ‘(Windows NT 10.0; WOW64)’, ‘(X11; Linux x86_64)’,
‘(Macintosh; Intel Mac OS X 10_12_6)’
]
chrome_version = ‘Chrome/{}.0.{}.{}’.format(first_num, third_num, fourth_num)

ua = ' '.join(['Mozilla/5.0', random.choice(os_type), 'AppleWebKit/537.36',
               '(KHTML, like Gecko)', chrome_version, 'Safari/537.36']
              )
return ua
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!