Python crawler: from introduction to abandonment

SunriseCai 2020-11-13 11:28:34
python crawler introduction abandonment

This blog is only for my spare time to record articles , Publish to , Only for users to read , If there is any infringement , Please let me know , I'll delete it .
This article is pure and wild , There is no reference to other people's articles or plagiarism . Insist on originality !!


Hello . Here is Python Reptiles from getting started to giving up series of articles . I am a SunriseCai.

Combined with video food , Better taste .

Selenium Crawling the commodity information of Jingdong Mall :

This article mainly introduces the use of Selenium The crawler program goes obtain Jingdong Mall The goods .

Baidu Encyclopedia :Selenium

 Insert picture description here
With the help of Selenium Can be very convenient for some simulation of human browser operation .
In other words ,selenium Will drive the browser to execute your commands .

First , It is suggested to move to official documents for systematic learning Selenium,Selenium Official documents
Selenium There is a lot of knowledge , Please refer to the official documents to learn the system .

1. install Selenium

Computer configuration selenium It only takes three steps to run the environment :

  1. install selenium modular
  2. download webdriver drive
  3. Configure environment variables

1.1 install selenium modular

  • install Selenium modular .

pip install selenium

1.2 download webdriver drive

  • Download a browser for webdriver drive , This article uses chrome Do a demonstration .
Bold style
  • See my chrome Version is 80.0.3987.149
     Insert picture description here
  • stay webdriver Download page here , To find the corresponding chrome Version of the driver can be downloaded .( As long as the version number is matched before , It doesn't have to be all the same )
     Insert picture description here

1.3 Configure environment variables

There are two ways to configure environment variables :

  1. Put it in Python Install under directory Scripts Inside the folder ;
  2. Specify... At the time of execution webdriver Drive path .

(1) Put it in Python Install under directory Scripts Inside the folder
 Insert picture description here

(2) Specify... At the time of execution webdriver Drive path .

For example, I will chromedriver.exe Drive on F The root directory of the disk , That's going on selenium It can be used when executable_path Appoint webdriver drive .

from selenium import webdriver
url = ''
browser = webdriver.Chrome(executable_path=r'F:\chromedriver.exe')

1.4 selenium A simple example

Or the code above , Use Baidu as an example .

from selenium import webdriver
url = ''
browser = webdriver.Chrome(executable_path=r'F:\chromedriver.exe') # Create a Google browser object
browser.get(url) # request url
browser.save_screenshot('baidu.jpg') # Screenshot
browser.quit() # Exit browser object

After code execution , You will find that there is an additional local folder named baidu.jpg Pictures of the , Look at the picture below .
 Insert picture description here

2. Analyze Jingdong Mall page

2.1 Analysis page

Open the home page , In the search box, type the product you want to search . Then click search
Here we use masks Product demonstration .
 Insert picture description here
Get the search box's xpath expression , Here's the picture :
 Insert picture description here
The code is as follows :

from selenium import webdriver
class JdSpider(object):
def __init__(self):
self.url = ''
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized") # Maximize the run window Don't add
self.browser = webdriver.Chrome(executable_path=r'F:\chromedriver.exe', options=options)
def __del__(self):
def search_goods(self):
self.browser.find_element_by_xpath('//*[@id="key"]').send_keys(' masks ') # Input content
self.browser.find_element_by_xpath('//*[@id="search"]/div/div[2]/button').click() # Simulation click button
if __name__ == '__main__':
spider = JdSpider()

The result of running the code is as follows :
 Insert picture description here

2.2 Data to be extracted

The next thing to extract is Price , Name of commodity , Number of evaluators , Shop name .
 Insert picture description here

The following parts will not be parsed , Have some homework left !!!

3. Complete code

The complete code can refer to this blog ,python Introduction to reptiles * selenium Crawl all the commodity information of JD – Click through , you 're right , It's also my water blog .

  • If you have any questions, please solve them by yourself , It is better to believe in books than to have no books .
  • It can't be solved. We can communicate with each other .

Finally, I will summarize the content of this chapter :

  1. It introduces Selenium Installation and configuration environment etc ;
  2. It introduces Selenium A simple example of ;
  3. The use of Selenium Crawler download Jingdong Mall The product information of .


  • Thank you for your patience in watching , Focus , Neverlost .
  • For the convenience of chicken pecking each other , Welcome to join QQ Group organization :648696280

Next article , be known as 《Python Reptiles from getting started to giving up 12 | Conclusion 》.


  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database