Home > OS >  The same crawler code, the results on the server and the local is not the same!
The same crawler code, the results on the server and the local is not the same!

Time:09-20

This is the result of the operation of the local


This is a service run results



This part is the core of this operation code:
` ` ` python
Def kuai_yun_qinghua_superfast () :

Url_kuai='https://www.kuaidaili.com/free/inha/{num}
Url_yun='http://www.ip3366.net/free/? Stype=1 & amp; Page={num} '
Url_qinghua='{num}/http://www.qinghuadaili.com/free/
Url_superfast='http://www.superfastip.com/welcome/freeip/{num}

Ip_list=[]
For j in range (4) :
If j==0:
Url=url_kuai
Elif j==1:
Url=url_yun
Elif j==2:
Url=url_qinghua
Elif j==3:
Url=url_superfast
For I in range (8) :
Temp_ip_list=[]
Url=url. The format (num=STR (I + 1))
Try:
Res=requests. Get (url=url, headers=headers)
Except (requests. Exceptions. ReadTimeout, requests. Exceptions. ChunkedEncodingError,
Requests. Exceptions. ConnectionError) as e:
Print (e)
The continue
HTML=etree. HTML (res) content)
Print (res) content. decode (' utf-8))
IP=HTML. Xpath ("//td [1] ")
Port=HTML. Xpath ("//td [2] ")
Print (IP)
Print (port)
Time. Sleep (2)
Temp_ip_list. The extend (list (map (lambda IP, port: (IP) text + + port ':') text), IP, port)))
Print (temp_ip_list)
If len (temp_ip_list) :
Ip_list [len (ip_list) : len (ip_list) + len (temp_ip_list) - 1]=temp_ip_list
# reset url
If j==0:
Url=url_kuai
Elif j==1:
Url=url_yun
Elif j==2:
Url=url_qinghua
Elif j==3:
Url=url_superfast

# remove duplicate elements
Ip_list=list (set (ip_list))
Return ip_list
` ` `

CodePudding user response:

Climb to the web on Linux server source code, I in the local use xpath to extract all success! But can only extract a data on the server,,,, I tried on the server reshipment LXML or not solve,,,,
  • Related