How to get data in python crawler
This article mainly introduces how to obtain data in python crawler. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!
Crawling data is actually a network request to the server based on a URL.
Get the data returned by the server.
Parse the data and convert the data returned by the server into an easy-to-understand style.
3. Filter the data and sift out the required data from a large amount of data.
4. Storage of information.
examples
from urllib.request import Requestfrom urllib.request import urlopen #Crawl Baidu homepage url1 = 'www.baidu.com'#Save request = Request(url= url1)response = urlopen(request)# print(response.read ().decode ('utf-8'))#Obtain data is source code to decode html_string = response.read().decode ('utf-8') with open ('baidu.html','w', encoding ='utf-8') as fp: fp.write(html_string) The above is "How to get data in python crawler" All the contents of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!