四川电信的 自动选号程序(未完成)

本来想写个四川电信的自动网上选号程序的。

获取候选号码的会话需要2次请求(一个GET 一个POST),spider会自动处理Cookie来维护session

采用scrapy完成,下面是spider的部分。

from scrapy.spider import BaseSpider
from scrapy.http import Request
from scrapy.conf import settings

import re
import urllib
#from jhl_utils.util import phone_re
phone_re = re.compile("(0{0,1}(13[0-9]|15[0,1,2,3,5-9]|18[6-9])[0-9]{8})")
from dianxin.items import DianxinItem

class PhoneSpider(BaseSpider):
    name = "phone"
    start_urls = [
        "http://sc.ct10000.com/service/transaction/xuanHao.jsp",
    ]

    def __init__(self, name=None, **kwargs):
        BaseSpider.__init__(self,name)

    def parse(self, response):
        for i in range(0,100):
            url = '''http://sc.ct10000.com/service/transaction/list.jsp''' + "?id="+ str(i)
            yield Request( url,method="POST",
                       body = "cityname=%B3%C9%B6%BC&citycode=0128&header=189&tailNum=" ,
                       headers ={'Content-Type': 'application/x-www-form-urlencoded'}
                       )    
        if( "list.jsp" in response.url):        
            ms = phone_re.findall(response.body)
            for m in ms:
                item = DianxinItem()
                item["phone"] = m[0]
                yield item

 未完成的代码则需要分析爬取的页面,获取/service/transaction/xuanHao_banli.jsp所需要的若干字段:

citycode=0128&cityname=%B3%C9%B6%BC

&sPrecontractNum=Y0tfa8xZRc%2FsHBDinoXssZGwbOt1TZLBQaM1j3wMdFE%3D

&empoent=10001

&module=ad9c1860ba10aaf6b0e23a5e90076657f9c4a1e0eb6aea43b623d7bbfd4d1de446d29d7e5435cde7957b46c910e56c4a2f15ddf3b98caabc9267ca3cc02fc8623c63ab74df0d3ff5b07efabba69ffd92f48cf28bc980e3bff447ab5d3f8fa09eaa1ce31aeeeb31b4f46739c57009d9673a51105491a446412e7584cb9f801fab

&oldNum=nfNtghXuVnCxqJpb9TYoYg%3D%3D

 

 

 

你可能感兴趣的:(scrapy,自动,四川电信,选号)