Python爬虫 百度360信息搜索并爬取

 对百度输入要搜索的信息,并怕去返回的网页信息

import requests
keyword = "Python"
try:
    kv = {'wd': keyword}
    r = requests.get('https://www.baidu.com/s', params=kv)
    print(r.request.url)
    r.raise_for_status()
    r.encoding = r.apparent_encoding
    print(len(r.text))
    
except:
    print("爬去失败")

输出:

https://www.baidu.com/s?wd=Python
227
>>> 

 

360搜索:

 

import requests
keyword = "Python"
try:
    kv = {'q': keyword}
    r = requests.get('https://www.so.com/s', params=kv)
    print(r.request.url)
    r.raise_for_status()
    r.encoding = r.apparent_encoding
    print(len(r.text))
    
except:
    print("爬去失败")

 

你可能感兴趣的:(Python网络爬虫与信息提取)