马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
刚学的抓取,上源码:import requests
from bs4 import BeautifulSoup
def get(keyword):
url="https://search.jd.com/Search?keyword={}&enc=utf-8".format(keyword)
headers={
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36',
'referer':"https://mall.jd.com/view_search-504374-14133499-99-1-24-1.html"
}
res = requests.get(url,headers=headers)
return res
def find(res):
soup = BeautifulSoup(res.text,'lxml')
target = soup.find_all("div",class_ = "p-name")
for each in target:
print(each.a.text,'\n')
def main():
keyword=input("搜索关键词:")
res = get(keyword)
find(res)
if __name__ == "__main__":
main()
|