当前位置:网站首页>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)
边栏推荐
- STM32 and motor development (from MCU to architecture design)
- php:&nbsp; The document cannot be displayed in Chinese
- 已解决TypeError: Argument ‘parser‘ has incorrect type (expected lxml.etree._BaseParser, got type)
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第四章习题】
- Flink SQL knows why (XIV): the way to optimize the performance of dimension table join (Part 1) with source code
- DQL basic query
- Finite State Machine FSM
- 开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...
- [data mining review questions]
- 阿南的疑惑
猜你喜欢

regular expression

Grid connection - Analysis of low voltage ride through and island coexistence
![[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number](/img/9d/6118b699c0d90810638f9b08d4f80a.jpg)
[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number

01 three solutions to knapsack problem (greedy dynamic programming branch gauge)

JSP and filter

已解决TypeError: Argument ‘parser‘ has incorrect type (expected lxml.etree._BaseParser, got type)

已解决(机器学习中查看数据信息报错)AttributeError: target_names

2022-02-14 incluxdb cluster write data writetoshard parsing

Flink code is written like this. It's strange that the window can be triggered (bad programming habits)

Flink SQL knows why (17): Zeppelin, a sharp tool for developing Flink SQL
随机推荐
Convolution emotion analysis task4
SSH login server sends a reminder
Flink SQL knows why (13): is it difficult to join streams? (next)
Dojo tutorials:getting started with deferrals source code and example execution summary
2022-02-11 heap sorting and recursion
剑指 Offer 17. 打印从1到最大的n位数
Reptile
How to get user location in wechat applet?
Server coding bug
已解决(机器学习中查看数据信息报错)AttributeError: target_names
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter III exercises]
【数据库原理及应用教程(第4版|微课版)陈志泊】【第四章习题】
Idea full text search shortcut ctr+shift+f failure problem
The difference between stratifiedkfold (classification) and kfold (regression)
MySQL constraints
[colab] [7 methods of using external data]
A large select drop-down box, village in Chaoyang District
Brief introduction to mvcc
Flink SQL knows why (XI): weight removal is not only count distinct, but also powerful duplication
[combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation