python点击网页按钮 没有id_的Python:点击一个按钮

1586010002-jmsa.png

I have problems in clicking this button that looks in HTML code like this:


Update:

I tried this, but it doesnt work:

form_data = urllib.urlencode({'Category' : '2', 'suid' : '19', 'deletetree' : '6', 'pushed' : 'Delete+Tree' })

urllib2.urlopen("management.php", form_data)

This is how I log in:

cj = cookielib.CookieJar()

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13')]

username = "user"

password = "pass"

USER_ID = '6'

loginonsite = login("http://mysite.com/myprofile.php",

"login_username=%s&login_password=%s&suid=%s".format(username, password, USER_ID)

)

解决方案

You could use requests to make a post.

import requests

data = {'Category' : '2', 'suid' : '19', 'deletetree' : '6', 'pushed' : 'Delete+Tree' }

response = requests.post('http://mysite.com/management.php', data=data)

print response.text

As more and more of the content of a webpage is generated in JavaScript I find myself using Selenium's webdriver to directly drive a real browser like Chrome when I'm doing this kind of automation now...

Update: Sounds like you need to login first

Now, requests can pass cookies through as well. So you to send a logged in request you would do this

login_data = data={'username': 'user', 'password': 'pass'

post_data = {

'Category' : '2', 'suid' : '19', 'deletetree' : '6', 'pushed' : 'Delete+Tree'

}

login_response = requests.get('http://mysite.com/myprofile.php', data=login_data)

form_response = requests.post(

'http://mysite.com/management.php',

data=post_data,

cookies=login_response.cookies

)

So, you do the login, then use the cookies in the response in the next request. Should work. But obviously I can't test that code for your exact situation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值