import re
import requests
from lxml import etree
url = ‘http://49.235.9’
r = requests.get(url)
#cook = r.cookies
‘’’
正则表达式方式取
token = re.findall(“name=‘csrfmiddlewaretoken’ value=’(.+?)’”, r.text)
print(token)
‘’’
demo = etree.HTML(r.text)
nodes = demo.xpath(’//input[@name=“csrfmiddlewaretoken”]’)[0].get(‘value’)
print(nodes)