当前位置:网站首页>Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
2022-07-03 13:16:00 【No envy】
Successfully solved :TypeError: Argument ‘parser‘ has incorrect type (expected lxml.etree._BaseParser, got type)
List of articles
Error code
My code :
import requests
import time
import random
from lxml import etree
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"}
def baidu_search(search_keyword, max_page):
for page in range(max_page):
time.sleep(random.randint(1, 2))
url = 'https://www.baidu.com/s?wd=%s' % search_keyword + '&pn=' + str(page * 10)
r = requests.get(url, headers=headers)
html = r.text
print(html)
html_data = etree.HTML(html, etree.HTMLParser)
# r1 = html_data.xpath('//h3')
# r2 = html_data.xpath('//*[@class="c-abstract"]')
# r3 = html_data.xpath('//*[@class="t"]/a/@href')
#
# for i in range(8):
# r11 = r1[i].xpath('string(.)')
# r22 = r2[i].xpath('string(.)')
# r33 = r3[i]
# print(r11)
def main():
rows = [(' My king sleeps '), ('Nike')]
max_page = 1
for search_keyword in rows:
baidu_search(search_keyword, max_page)
if __name__ == '__main__':
main()
Wrong content :
Traceback (most recent call last):
File "E:/Python/3.py", line 54, in <module>
main()
File "E:/Python/3.py", line 46, in main
baidu_search(search_keyword, max_page)
File "E:/Python/3.py", line 29, in baidu_search
html_data = etree.HTML(html,etree.HTMLParser)
TypeError: Argument 'parser' has incorrect type (expected lxml.etree._BaseParser, got type)
Error reason
Translation of error reporting content :TypeError: Parameters “parser” The type of is incorrect ( Should be lxml.etree.\u BaseParser,get type)
resolvent
Replace the parsing code with :
html_data = etree.HTML(html)
边栏推荐
- 剑指 Offer 11. 旋转数组的最小数字
- The difference between session and cookie
- 剑指 Offer 14- II. 剪绳子 II
- Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
- (first) the most complete way to become God of Flink SQL in history (full text 180000 words, 138 cases, 42 pictures)
- In the promotion season, how to reduce the preparation time of defense materials by 50% and adjust the mentality (personal experience summary)
- mysqlbetween实现选取介于两个值之间的数据范围
- 已解决TypeError: Argument ‘parser‘ has incorrect type (expected lxml.etree._BaseParser, got type)
- 高效能人士的七个习惯
- Create a dojo progress bar programmatically: Dojo ProgressBar
猜你喜欢
Deeply understand the mvcc mechanism of MySQL
Annotation and reflection
STM32 and motor development (from MCU to architecture design)
106. 如何提高 SAP UI5 应用路由 url 的可读性
Sword finger offer 12 Path in matrix
18W word Flink SQL God Road manual, born in the sky
The difference between stratifiedkfold (classification) and kfold (regression)
Elk note 24 -- replace logstash consumption log with gohangout
人身变声器的原理
01 three solutions to knapsack problem (greedy dynamic programming branch gauge)
随机推荐
How to get user location in wechat applet?
剑指 Offer 16. 数值的整数次方
2022-02-14 analysis of the startup and request processing process of the incluxdb cluster Coordinator
C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - cases without asynchronous
MySQL constraints
Leetcode234 palindrome linked list
显卡缺货终于到头了:4000多块可得3070Ti,比原价便宜2000块拿下3090Ti
Logback log framework
用户和组命令练习
Detailed explanation of multithreading
Create a dojo progress bar programmatically: Dojo ProgressBar
DQL basic query
71 articles on Flink practice and principle analysis (necessary for interview)
Solve system has not been booted with SYSTEMd as init system (PID 1) Can‘t operate.
Kotlin - improved decorator mode
sitesCMS v3.1.0发布,上线微信小程序
Logback 日志框架
sitesCMS v3.0.2发布,升级JFinal等依赖
【数据库原理及应用教程(第4版|微课版)陈志泊】【第三章习题】
剑指 Offer 17. 打印从1到最大的n位数