def pa():
#打开文件txt文件,文件内容请看博客:伪装浏览器报头
with open('C:/Users/黑神/Desktop/爬虫/html爬虫伪装头.txt', 'r', encoding='utf-8') as f:
a = f.readlines()
for i in a:
a = i
a = eval(a)
ua=a
a=random.choice(ua)
return a
动态ip地址
def mip():
#第一种方法是从本地txt里获取
# 1.文件获取
# with open('C:/Users/黑神/Desktop/爬虫/代理ip地址.txt', 'r', encoding='utf-8') as f:
# a = f.readlines()
# for i in a:
# a = i
# a = eval(a)
#
# a1=a
# a = random.choice(a1)
# return a
# 2.从网页获得代理
#代理网页是从淘宝买的动态ip地址
url='http://www.httpipqq.com/api.asp?sl=10&noinfo=true&ddbh=205381257343363825'
req=requests.get(url)
html=req.text
# 动态ip地址,获得网页内容并且去掉没用的特殊符号
html=html.split('\r\n')
html.pop()
a = random.choice