当前位置:网站首页>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)
边栏推荐
- sitesCMS v3.0.2发布,升级JFinal等依赖
- 这本数学书AI圈都在转,资深ML研究员历时7年之作,免费电子版可看
- R语言gt包和gtExtras包优雅地、漂亮地显示表格数据:nflreadr包以及gtExtras包的gt_plt_winloss函数可视化多个分组的输赢值以及内联图(inline plot)
- 2022-02-09 survey of incluxdb cluster
- 显卡缺货终于到头了:4000多块可得3070Ti,比原价便宜2000块拿下3090Ti
- Kotlin - 改良装饰者模式
- C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - using asynchronous
- Seven second order ladrc-pll structure design of active disturbance rejection controller
- Fabric.js 更换图片的3种方法(包括更换分组内的图片,以及存在缓存的情况)
- CVPR 2022 image restoration paper
猜你喜欢
[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
Flink SQL knows why (XI): weight removal is not only count distinct, but also powerful duplication
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [sqlserver2012 comprehensive exercise]
My creation anniversary: the fifth anniversary
Logseq 评测:优点、缺点、评价、学习教程
我的创作纪念日:五周年
剑指 Offer 14- II. 剪绳子 II
今日睡眠质量记录77分
【数据库原理及应用教程(第4版|微课版)陈志泊】【第四章习题】
2022-02-09 survey of incluxdb cluster
随机推荐
Mysqlbetween implementation selects the data range between two values
Fabric.js 更换图片的3种方法(包括更换分组内的图片,以及存在缓存的情况)
2022-02-11 practice of using freetsdb to build an influxdb cluster
Leetcode234 palindrome linked list
Smbms project
【習題五】【數據庫原理】
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [sqlserver2012 comprehensive exercise]
When the R language output rmarkdown is in other formats (such as PDF), an error is reported, latex failed to compile stocks Tex. solution
Sitescms v3.1.0 release, launch wechat applet
sitesCMS v3.1.0发布,上线微信小程序
Flink SQL knows why (XI): weight removal is not only count distinct, but also powerful duplication
Oracle memory management
[combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation
01 three solutions to knapsack problem (greedy dynamic programming branch gauge)
php:&nbsp; The document cannot be displayed in Chinese
Huffman coding experiment report
2022-01-27 redis cluster brain crack problem analysis
Tencent cloud tdsql database delivery and operation and maintenance Junior Engineer - some questions of Tencent cloud cloudlite certification (TCA) examination
对业务的一些思考
剑指 Offer 14- II. 剪绳子 II