python3.x: Proxy IP Brush likes

Source: Internet
Author: User

python3.x: Proxy IP Brush likes

One, function:

For a website to the enterprise automatic brush point like;

Website:https://best.zhaopin.com/

Two, step:

1, get proxy IP (proxy IP address:http://www.xicidaili.com/nn);

2, simulate the browser to open the likes page;

3, simulate the likes of the event, and pass parameters;

Parameter acquisition: According to the browser's developer tools, tracking the likes of the event, the corresponding "Network" can see the relevant header information, where the from data is the parameter information;

Third, the code:

#Python3#function: To the https://best.zhaopin.com/in the Enterprise brush likesImportReImportRandomImportSYSImport TimeImportdatetimeImportThreading fromRandomImportChoiceImportRequestsImportBS4#set up the User-agent list, and on each request, you can randomly pick a user-agnet in this listUser_agent = [    "mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:17.0; baiduspider-ads) gecko/17.0 firefox/17.0",    "mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; RV:1.9B4) gecko/2008030317 firefox/3.0b4",    "mozilla/5.0 (Windows; U MSIE 6.0; Windows NT 5.1; SV1;. NET CLR 2.0.50727; Bidubrowser 7.6)",    "mozilla/5.0 (Windows NT 6.3; WOW64; trident/7.0; rv:11.0) Like Gecko",    "mozilla/5.0 (Windows NT 6.3; WOW64; rv:46.0) gecko/20100101 firefox/46.0",    "mozilla/5.0 (Windows NT 6.3; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.99 safari/537.36",    "mozilla/5.0 (Windows NT 6.3; Win64; x64; trident/7.0; Touch; LCJB; rv:11.0) Like Gecko",    ]    #Domestic High Stealth proxy IP, returns all IPs for the current pagedefget_ip_list ():#Get proxy IP (take the IP list of the current page, 100 IP per page)URL ="Http://www.xicidaili.com/nn"Headers= {"Accept":"Text/html,application/xhtml+xml,application/xml;",                "accept-encoding":"gzip, deflate, SDCH",                "Accept-language":"zh-cn,zh;q=0.8,en;q=0.6",                "Referer":"http://www.xicidaili.com",                "user-agent":"mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/42.0.2311.90 safari/537.36"} R= Requests.get (url,headers=headers) Soup= BS4. BeautifulSoup (R.text,'Html.parser') Data= Soup.table.find_all ("TD")    #matching rules need to be viewed in the browser's developer tools    #Match ip:<td>61.135.217.7</td>Ip_compile= Re.compile (r'<td> (\d+\.\d+\.\d+\.\d+) </td>')    #Matching Port:<td>80</td>Port_compile = Re.compile (r'<td> (\d+) </td>')       #get all IPs, return an array []IP =Re.findall (IP_COMPILE,STR (data))#Get ALL ports: Returns an array []Port =Re.findall (PORT_COMPILE,STR (data))#combine ip+ ports, such as: 61.135.217.7:80    return[":". Join (i) forIinchzip (ip,port)]#Open the page. Perform the likes behavior.defDo_dz (code=0,ips=[]):    #Like , if the proxy IP is not available to praise the failure, it will be automatically replaced by a proxy IP to continue to like    Try:        #randomly select an IPIP =Choice (IPs)except:        returnFalseElse: Proxies= {            "http": IP,} headers_= {            "Accept":"*/*",            "accept-encoding":"gzip, deflate, SDCH",            "Accept-language":"zh-cn,zh;q=0.8,en;q=0.6",            "Referer":"https://best.zhaopin.com/",            "user-agent": Choice (user_agent),}#use the browser's developer tools to track the values of the parameters that are transmitted by the likes eventDatas = {'Bestid': 6030,'Source':' Best'}    Try:         #likes URLUrl_dz ="https://best.zhaopin.com/API/Vote.ashx"          #Perform the likes behavior (send request)R_dz = Requests.post (url_dz,headers=headers_,data=datas,proxies=proxies)exceptRequests.exceptions.ConnectionError:Print("Connection Error")        if  notIPs:Print("Not IP") Sys.exit ()#Remove an unavailable proxy IP        ifIpinchips:ips.remove (IP)#re-request URLGet_url (code,ips)Else:        #Get current TimeDate = Datetime.datetime.now (). Strftime ('%h:%m:%s')        Print(U"%s times [%s] [%s]: poll%s (number of available proxy IP:%s)"%(Code,date,ip,r_dz.text,len (IPS)))if __name__=='__main__': IPs= []    #Python3 integrates xrange () with rang () e as a range ()     forIinchRange (5000):        #re-fetch the latest proxy IP every 1000 times        ifI% 1000 = =0:ips.extend (Get_ip_list ())#threads are enabled and a thread is generated at 2-second intervalsT1 = Threading. Thread (target=do_dz,args=(i,ips)) T1.start ()#the smallest unit of time.sleep is millisecondsTime.sleep (2)

python3.x: Proxy IP Brush likes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.