Python如何实现自动访问网页功能


本文摘自php中文网,作者零到壹度,侵删。


本篇文章给大家分享的内容是Python如何实现自动访问网页功能 ,主要以代码的形式展现,有着一定的参考价值,有需要的朋友可以参考一下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

import urllib.request

import requests

import time

import ssl

import random

 

def openUrl(ip, agent):

    headers = {'User-Agent': agent}   

    proxies = {'http' : ip}   

    requests.get("https://www.baidu.com", headers=headers, proxies=proxies, verify=True)   

    ssl._create_default_https_context = ssl._create_unverified_context   

    print("Access to success.")

     

#IP池

#IP来源:

def randomIP():

    ip = random.choice(['120.78.78.141', '122.72.18.35', '120.92.119.229'])   

    return ip

     

#User-Agent

#User-Agent来源:

def randomUserAgent():

    UserAgent = random.choice(['Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',                             

                               'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36',                             

                               'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36'])   

    return UserAgent

     

if __name__ == '__main__':

    for i in range(10):  

         ip = randomIP()       

         agent = randomUserAgent()       

         openUrl(ip, agent)       

         time.sleep(1)

相关推荐:

WebSpec自动访问页面的使用

模拟HTTP请求实现网页自动操作及数据采集

以上就是Python如何实现自动访问网页功能的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

怎么获得一个字符串的子串

Python flask 多对多表查询的实例详解

Python实现的hmacmd5加密算法示例_Python

Python中生成器和迭代器的简单介绍(附示例)

Python mysql数据库中pymysqlpool是如何使用的?

matplotlib中对图形颜色和线条的填充

嵌入式软件和Python有关吗

Python下载模块然后怎么安装

Python中文件操作的相关内容总结(附示例)

Python list有序吗

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...