Python爬虫小记

it2022-05-05  148

1.selenium窗口无限向下滚动:

使用脚本‘window.scrollBy(0, 1000)',加while True循环,示例代码:

js = 'window.scrollBy(0, 1000)' driver.execute_script(js)

 参考:https://blog.csdn.net/Sily_Z/article/details/80733267

 

2.爬虫中\xa0等字符的解释及去除方法

\xa0表示不间断空白符。在Python中,使用re.sub方法不能将其去除,但有以下两种方法可行:

2.1、使用translate方法,示例:

>>> inputstring = u'\n Door:\xa0Novum \t ' >>> move = dict.fromkeys((ord(c) for c in u"\xa0\n\t")) >>> output = inputstring.translate(move) >>> output ' Door:Novum '

2.2、利用split()方法,示例:

>>> s 'T-shirt\xa0\xa0短袖圆领衫,体恤衫\xa0' >>> out = "".join(s.split()) >>> out 'T-shirt短袖圆领衫,体恤衫'

参考:https://blog.csdn.net/wangbowj123/article/details/78061618

转载于:https://www.cnblogs.com/hifinancial/p/9674521.html


最新回复(0)