Climber – General Code Framework

1. Baidu search keyword submission

The format of Baidu search path is: http://www.baidu.com/s?wd=keyword

import requests

keyword
= "Python"
try:
kv
= {'wd': keyword}
url
= "http://www.baidu.com/s "
r
= requests.get(url, params=kv)   # Insert the corresponding search keyword at the end of the url
# print(r.request.url)
r.raise_for_status()
# print(len(r.text))
catch:
print("Crawl failed")

2. Web image crawling

import requests

import os

root
= "D://pics// "
url
= "http://img0.dili360.com/ga /M01/43/32/wKgBy1diUTyAJgSmADRkvfSqZo0372.tub.jpg"
path = root + url.split('/')[-1]    # Use The name of the website picture is used as the storage file name

try:
  if not os.path.exists(root):    # If the storage directory does not exist, create it
    os.mkdir(root)
  if not os.path.exists(path) :    
    r
= requests.get(url)
    with open(path,
'wb') as f:
      f.write(r.content)
      f.close()
      print("Save successfully")
  else:
     print("File already exists")
"except: print("Failed to crawl")" )

3. Submit the IP address to IP138 for query

< span style="color: #0000ff;">import requests

import os

ip
= "202.204.80.112"
raw_url
= ''http://www.ip138.com/ips138.asp?ip="
url = raw_url + ip
try:
  r
= requests.get(url)  r.raise_for_status()  r.encoding = r.apparent_encoding  print(r.text[-500:])except:  print("crawl failed")< /pre>

import requests

keyword
= "Python"
try:
kv
= {'wd': keyword}
url
= "http://www.baidu.com/s "
r
= requests.get(url, params=kv)   # Insert the corresponding search keyword at the end of the url
# print(r.request.url)
r.raise_for_status()
# print(len(r.text))
catch:
print("Crawl failed")

import requests

import os

root
= "D://pics// "
url
= "http://img0.dili360.com/ga /M01/43/32/wKgBy1diUTyAJgSmADRkvfSqZo0372.tub.jpg"
path = root + url.split('/')[-1]    # Use The name of the website picture is used as the storage file name

try:
  if not os.path.exists(root):    # If the storage directory does not exist, create it
    os.mkdir(root)
  if not os.path.exists(path) :    
    r
= requests.get(url)
    with open(path,
'wb') as f:
      f.write(r.content)
      f.close()
      print("Save successfully")
  else:
     print("File already exists")
"except: print("Failed to crawl")" )

import requests

import os

ip = "202.204.80.112"

raw_url
= ''http://www.ip138.com/ips138.asp?ip="

url = raw_url + ip

try:

  r
= requests.get(url)  r.raise_for_status()  r.encoding = r.apparent_encoding  print(r.text[-500:])except:  print("crawl failed")< /pre>

Leave a Comment

Your email address will not be published.