当前位置:网站首页>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)
边栏推荐
- 这本数学书AI圈都在转,资深ML研究员历时7年之作,免费电子版可看
- 2022-02-11 heap sorting and recursion
- Flink SQL knows why (13): is it difficult to join streams? (next)
- Some thoughts on business
- Logback log framework
- MySQL
- C graphical tutorial (Fourth Edition)_ Chapter 13 entrustment: what is entrustment? P238
- In the promotion season, how to reduce the preparation time of defense materials by 50% and adjust the mentality (personal experience summary)
- CVPR 2022 image restoration paper
- Flink SQL knows why (16): dlink, a powerful tool for developing enterprises with Flink SQL
猜你喜欢

Flink SQL knows why (19): the transformation between table and datastream (with source code)

Sitescms v3.1.0 release, launch wechat applet

mysql更新时条件为一查询

Analysis of the influence of voltage loop on PFC system performance

【数据库原理及应用教程(第4版|微课版)陈志泊】【第三章习题】

2022-02-14 incluxdb cluster write data writetoshard parsing
[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈..."/>开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...

【数据库原理及应用教程(第4版|微课版)陈志泊】【第四章习题】

MySQL_ JDBC

When the R language output rmarkdown is in other formats (such as PDF), an error is reported, latex failed to compile stocks Tex. solution
随机推荐
The difference between session and cookie
mysql更新时条件为一查询
File uploading and email sending
Reptile
【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
Useful blog links
Elk note 24 -- replace logstash consumption log with gohangout
2022-01-27 redis cluster technology research
regular expression
剑指 Offer 12. 矩阵中的路径
JSP and filter
Logback log framework
Server coding bug
Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
【R】【密度聚类、层次聚类、期望最大化聚类】
Sitescms v3.0.2 release, upgrade jfinal and other dependencies
Servlet
Setting up Oracle datagurd environment
双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter 6 exercises]