Python crawler programming idea (59): get attribute value and text with beautiful soup CSS selector

Mona lining 2021-11-25 10:17:45
python crawler programming idea attribute

         because select Method also returns Tag A collection of objects , So you can use Tag Object to get the node attribute value and text content . To get the property value, you can use attrs, It can also be used directly [...] Refers to the attributes of the node . To get the text content of the node, you can use get_text Method , You can also use string attribute .

The following example uses CSS The selector selects a specific a node , And get the a Node href Attribute value and text content .

from bs4 import BeautifulSoup
html = '''
<div>
<ul>
<li class="item1" value1="1234" value2 = "hello world">
<a href="https://geekori.com"> geekori.com</a>
</li>
<li class="item">
<a href="https://www.jd.com"> Jingdong Mall </a>
<a href="https://www.google.com"> Google </a>
</li>
</ul>
<ul>
<li class="item3"&g
版权声明
本文为[Mona lining]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/11/20211109005652436v.html

  1. Pandas draws line chart, bar chart and bar chart
  2. Exploration and practice of easy transformation between various data structures in Python
  3. A simple practice of Python list generation
  4. Use Python to guess the number of machines and judge the number of guesses
  5. Question about Python: did you learn Python
  6. 20210928 | Python case: building tax calculation function
  7. Python basic syntax collation
  8. Some small accumulation of writing programs in python (4)
  9. Some small accumulation of writing programs in python (3)
  10. Python leak detection tips (3)
  11. Python leak detection tips (2)
  12. Python leak detection tips (1)
  13. Python foundation and MySQL Foundation
  14. Some small accumulation of writing programs in python (2)
  15. Some small accumulation of writing programs in Python
  16. Python 3.7.3 + cuda9.2 installing Python
  17. Python knowledge used to write programs
  18. Python installation + vscode configuration Python environment
  19. Some small problems during Python installation
  20. Answer and Q & A of Python practice introduction course
  21. Sorting out the learning route for Python beginners
  22. The 6-line Python code uses the pdf2docx module converter object to convert PDF into docx file
  23. Batch compression of picture files using Python
  24. Using Python to write djikstra algorithm for robot path planning
  25. python实现手机号获取短信验证码 | 对接打码平台
  26. Detailed explanation of Euler Rodriguez code in Python
  27. Prove that angular displacement is not a vector with Python
  28. Using Python program to deeply understand homogeneous transfer matrix t
  29. Triple product formula of vector and its proof (with Python code)
  30. Derivation of differential formula of DH matrix using Python
  31. Python openpyxl operation on Excel (get the total number of columns, get the value of a row, get the value of a column, and set the cell value)
  32. Realizing Excel data filtering and data matching with Python
  33. Python reads and writes files
  34. Four scenarios of processing Excel files with Python
  35. Python converts dictionary to excel
  36. Python implements file reading and writing
  37. Basic Python syntax -- functions
  38. Python learning thinking
  39. Python basic syntax -- Boolean operation, break, continue, pass
  40. Python basic syntax -- loop
  41. Basic Python syntax -- lists, dictionaries
  42. Python basic syntax -- conditional judgment, input ()
  43. Python first experience - efficient office, data analysis, crawler
  44. Modulenotfounderror: no module named 'Django summernote details
  45. Key points for Django to make personal blog website
  46. Path setting of templates in Django settings
  47. Leetcode 1611. Minimum one bit operations to make integers Zero (Python)
  48. Directory C: \ users \ a \ desktop \ Django_ The blog master is registered as the GIT root, but no git repository details are found there
  49. Django. Core. Exceptions. Improveconfigured: application labels aren't unique, duplicates: admin
  50. How to verify that Django has created the project details correctly
  51. How to create a database when using Django to construct a website
  52. The solution of using Django framework to create project in Windows system
  53. Running Python virtual environment on win10 system to execute ll_ Env \ scripts \ activate: unable to load file elaboration scheme
  54. Detailed explanation of constructing virtual environment with Django in Python 3
  55. Python implementation of affine cipher
  56. RC4 Python implementation
  57. Simple: Python_ Automatic body temperature clock
  58. 用python把两个csv中的日期的列提出年,做出新的一列,再把两个csv表格按照新做出的日期这列和ID号合并为一个表。
  59. python中类实例化后,其对象无法被其他模块调用方法
  60. [JSON] - Python creates JSON file format