当前位置:网站首页>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)
边栏推荐
- Solve system has not been booted with SYSTEMd as init system (PID 1) Can‘t operate.
- [Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter 6 exercises]
- 阿南的疑惑
- Huffman coding experiment report
- 2022-02-11 practice of using freetsdb to build an influxdb cluster
- Setting up Oracle datagurd environment
- Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
- The 35 required questions in MySQL interview are illustrated, which is too easy to understand
- [combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation
- SSH login server sends a reminder
猜你喜欢

mysql更新时条件为一查询

这本数学书AI圈都在转,资深ML研究员历时7年之作,免费电子版可看

我的创作纪念日:五周年

Leetcode234 palindrome linked list
[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈..."/>开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...

用户和组命令练习

Some thoughts on business
![[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter 6 exercises]](/img/c0/92e9e52f1f643b66720697523a1794.png)
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter 6 exercises]

Flink SQL knows why (XIV): the way to optimize the performance of dimension table join (Part 1) with source code

Detailed explanation of multithreading
随机推荐
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter III exercises]
Flink code is written like this. It's strange that the window can be triggered (bad programming habits)
sitesCMS v3.0.2发布,升级JFinal等依赖
Server coding bug
sitesCMS v3.1.0发布,上线微信小程序
IDEA 全文搜索快捷键Ctr+Shift+F失效问题
Sword finger offer 11 Rotate the minimum number of the array
【習題五】【數據庫原理】
用户和组命令练习
今日睡眠质量记录77分
Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
Slf4j log facade
【历史上的今天】7 月 3 日:人体工程学标准法案;消费电子领域先驱诞生;育碧发布 Uplay
剑指 Offer 17. 打印从1到最大的n位数
Logback 日志框架
Idea full text search shortcut ctr+shift+f failure problem
解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.
已解决TypeError: Argument ‘parser‘ has incorrect type (expected lxml.etree._BaseParser, got type)
Reptile
elk笔记24--用gohangout替代logstash消费日志