首页 > 代码库 > http请求模块

http请求模块

自己写了个http请求模板,方便爬虫调取。
# coding:utf-8 import requests from fake_useragent import UserAgent from random import choice # 通用性http请求模块 class model_of_request: def __init__(self): self.urls = ‘http://1212.ip138.com/ic.asp‘ self.is_active_proxy_ip = [] # 获取user-agent def get_user_agent(self): ua = UserAgent() headers = {‘User-Agent‘: ua.random} return headers # 将post请求转换字典 def postdata_to_dict(self, response): data = http://www.mamicode.com/{}>

  

http请求模块