Spiderbuf
爬虫练习
Python习题
技术文章
在线工具
捐赠
S02 - http请求分析及头构造使用
发布日期:
1718093606
阅读数:863
coding=utf-8 import requests from lxml import etree url = ‘https://spiderbuf.cn/web-scraping-practice/scraper-http-header’ myheaders = {‘User-Agent’:‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36&rsqu...
S01 - requests库及lxml库入门
发布日期:
1718093235
阅读数:1427
coding=utf-8 import requests from lxml import etree url = ‘https://spiderbuf.cn/web-scraping-practice/requests-lxml-for-scraping-beginner’ html = requests.get(url).text f = open(‘01.html’, ‘w’, encoding=‘utf-8’) f.write(html) f.close() root = etree.HTM...
Python调用Selenium爬取网页
发布日期:
1718092674
阅读数:1096
# coding=utf-8 from selenium import webdriver if __name__ == '__main__': url = 'http://www.example.com' client = webdriver.Chrome() client.get(url) html = client.page_source print(html) client.quit()...
Python解析Json字符串
发布日期:
1718092557
阅读数:976
# coding=utf-8 import json if __name__ == '__main__': json_str = '{"website":"Spiderbuf", "url":"http://www.spiderbuf.cn","description":"Python爬虫练习网站"}' json_obj = json.loads(json_str) print(json_obj['website'])...
Python爬取图片并保存
发布日期:
1718092472
阅读数:997
# coding=utf-8 import requests # 请求远程图片的函数,参数url为图片的完整链接,函数返回请求回来的二进制内容 def get_content(url): # 准备好User-Agent到变量myheaders myheaders = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36'} response = requests...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21