tl_tl 发表于 2019-4-13 20:54:00

闲来无事看到别人发的投票链接,就想用爬虫实现自动刷票来练手,最后一步遇到问题

以下是我写的源代码,可以看看,看看我的问题到底出在哪里,我始终收不到返回值,但是状态码是200,是header有错还是form表单的问题呢,这个投票是根据ip来的,切换ip可无限投,谢谢大家了

# coding=utf-8
import requests
from lxml import etree
import tesserocr
from PIL import Image
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36',
}
def vote():

    #rep = requests.get('http://127.0.0.1:5000/get', headers=header)
    #prox = {
    #    "http": "http://" + rep.text
    #}
    #print(prox)
    url = 'http://manage.life.aaej.cn/web/vote/votedetail?id=144&from=groupmessage'
    session = requests.Session()
    response = session.get(url = url,headers = header)
    print("cook:",response.cookies)
    html = etree.HTML(response.text)
    guid = html.xpath(r'//div[@id="votebystu"]/div/input/@value')
    imgUrl = html.xpath(r'//img[@id="yzm2"]/@src')
    imgUrl = 'http://manage.life.aaej.cn'+imgUrl

    img = requests.get(imgUrl)

    with open('imgCode.jpg','wb') as f:
      f.write(img.content)

    result = viewImg().replace(' ','')
    print(result)
    data = {
      'votetype': '2',
      'guid' : guid,
      'authcode': result.strip()
    }
    url = 'http://manage.life.aaej.cn/web/vote/vote'
    rep = session.post(url = url,headers = header,data = data)
    print(data)
    print(rep.text)
    print("code:",rep.status_code)

def viewImg():
    image = Image.open('imgCode.jpg')

    image = image.convert('L')
    threhold = 127
    table = []
    for i in range(256):
      if i < threhold:
            table.append(0)
      else:
            table.append(1)

    image = image.point(table, '1')

    result = tesserocr.image_to_text(image)

    return result



vote()

采茝. 发表于 2021-1-29 19:11:39

插眼
页: [1]
查看完整版本: 闲来无事看到别人发的投票链接,就想用爬虫实现自动刷票来练手,最后一步遇到问题