导航:首页 > 编程语言 > python模拟访问网页

python模拟访问网页

发布时间:2023-04-28 06:33:25

❶ 想用python编写一个脚本,登录网页,在网页里做一系列操作,应该怎样实现

python编写一个脚本腊厅的具体操作:

1、首先,打开python并创建一个新的PY文件。

❷ 如何用python访问网页并在表单处输入内容

我用过selenium模拟浏览器
使用selenium的chrome或firefox的webdriver打开浏览器
driver.get(url) #访问你的网页from=driver.find_elements_by_xpath("xxx")通过xpath或id等方法锁定到网页上表单的那个元素后,用
from.send_keys("xxx")来输入内容

❸ python3.6怎么访问网页

使用Python访问网页主要有三种方式: urllib, urllib2, httplib
urllib比较简单,功能相对也比较弱,httplib简单强大,但好像不支持session
1. 最简单的页面访问
res=urllib2.urlopen(url)
print res.read()
2. 加上要get或post的数据
data={"name":"hank", "passwd":"hjz"}
urllib2.urlopen(url, urllib.urlencode(data))
3. 加上http头
header={"User-Agent": "Mozilla-Firefox5.0"}
urllib2.urlopen(url, urllib.urlencode(data), header)使用opener和handler
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
4. 加上session
cj = cookielib.CookieJar()
cjhandler=urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cjhandler)
urllib2.install_opener(opener)
5. 加上Basic认证
password_mgr = urllib2.()
top_level_url = "http://www.163.com/"
password_mgr.add_password(None, top_level_url, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
6. 使用代理
proxy_support = urllib2.ProxyHandler({"http":"http://1.2.3.4:3128/"})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
7. 设置超时
socket.setdefaulttimeout(5)

❹ 怎么python 模拟网站登录、注册

将注册名和密码存到字典中,下次登陆时就可以判断是否对应

❺ python获取cookie后怎么模拟登陆网站

运行平台:Windows

Python版本:Python3.x

IDE:Sublime text3

一、为什么要使用Cookie

Cookie,指某些网站为了辨别用户身份、进行session跟踪而储存在用户本地终端上的数据(通常经过加密)。
比如说有些网站需要登录后才能访问某个页面,在登录之前,你想抓取某个页面内容,登陆前与登陆后是不同的,或者不允许的。
使用Cookie和使用代理IP一样,也需要创建一个自己的opener。在HTTP包中,提供了cookiejar模块,用于提供对Cookie的支持。

三、总结

获取成功!如果看过之前的笔记内容,我想这些代码应该很好理解吧。

❻ python爬虫模拟登陆网站

你可以结合使用requests和selenium这两个python模块来实现半自动化模拟登录。

#-*-coding:utf-8-*-
importtime
importrequests
fromrequests.sessionsimportcookiejar_from_dict
fromseleniumimportwebdriver

LOGIN_URL='http://www.cofool.com/'

driver=webdriver.Firefox()
driver.get(LOGIN_URL)
time.sleep(30)

cookies={}
forcookieindriver.get_cookies():
cookies[cookie['name']]=cookie['value']
driver.quit()
printcookies

#cookies={}

headers={
'User-Agent':'Mozilla/5.0(WindowsNT6.1;WOW64;rv:24.0)Gecko/20100101Firefox/24.0',
'Accept':'*/*',
'Connection':'keep-alive',
}
cookies=cookiejar_from_dict(cookies)

rep=requests.get('http://www2.cofool.com/stock/mainzjgp.asp',cookies=cookies,headers=headers)
printrep.text

如果解决了您的问题请采纳!

如果未解决请继续追问

阅读全文

与python模拟访问网页相关的资料

热点内容
c51单片机原 浏览:196
交行app在哪里买东西 浏览:39
python高手之路pdf 浏览:84
iphone怎么像安卓一样返回 浏览:162
linuxtomcat端口占用怎么办 浏览:722
表演pdf 浏览:923
微信如何更换服务器 浏览:861
android使用html5 浏览:460
python可视化极坐标 浏览:386
程序员喜欢绿色 浏览:732
php编译的主流软件 浏览:366
操作系统服务器版本下载地址 浏览:247
手机管家加密图片打不开 浏览:841
基于单片机的智能散热器控制器的设计 浏览:473
pdfadobereaderxi 浏览:490
本田雅阁压缩机工作 浏览:682
河北编程排行榜 浏览:136
胸椎12轻度压缩性骨折 浏览:106
算法英文pdf 浏览:360
编译原理第3版清华课后答案第二章 浏览:167