<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python Archives - CNERIS</title>
	<atom:link href="https://cneris.com/en/category/python-en/feed/" rel="self" type="application/rss+xml" />
	<link>https://cneris.com/en/category/python-en/</link>
	<description></description>
	<lastBuildDate>Wed, 02 Oct 2024 16:32:25 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Traffic Bot in Python</title>
		<link>https://cneris.com/en/traffic-bot-in-python/</link>
					<comments>https://cneris.com/en/traffic-bot-in-python/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 02 Oct 2024 16:32:25 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[traffic bot]]></category>
		<category><![CDATA[traffic box python]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2329</guid>

					<description><![CDATA[<p>There is a Traffic Bot written in Python that can be used to generate automated web traffic. This type of bot can be useful for performance testing, user simulation, or web development experiments. Below is an example of code and a small usage guide. Python Code Example: This script uses the requests library to simulate [...]</p>
<p>The post <a href="https://cneris.com/en/traffic-bot-in-python/">Traffic Bot in Python</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There is a <strong>Traffic Bot</strong> written in <strong>Python</strong> that can be used to generate automated web traffic. This type of bot can be useful for performance testing, user simulation, or web development experiments. Below is an example of code and a small usage guide.</p>
<h4>Python Code Example:</h4>
<p>This script uses the <strong>requests</strong> library to simulate multiple visits to a specific URL.</p>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="flex items-center text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"><span class="hljs-keyword">import</span> requests<br />
<span class="hljs-keyword">import</span> time</code></code><span class="hljs-comment"># URL of the website you want to visit</span><br />
url = <span class="hljs-string">&#8216;https://your-site.com&#8217;</span></p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code><span class="hljs-comment"># Number of visits you want to make</span><br />
visits = <span class="hljs-number">100</span></p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code><span class="hljs-comment"># Time interval between visits in seconds</span><br />
interval = <span class="hljs-number">5</span></p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(visits):<br />
response = requests.get(url)<br />
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&#8217;Visit <span class="hljs-subst">{i+<span class="hljs-number">1</span>}</span>: <span class="hljs-subst">{response.status_code}</span>&#8216;</span>)<br />
time.sleep(interval)</p>
</div>
</div>
<h4>Usage Guide:</h4>
<ol>
<li><strong>Installing Dependencies</strong>: You need to install the <code>requests</code> library to run this script:
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-main-surface-secondary px-2 font-sans text-xs text-token-text-secondary"></div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">pip install requests<br />
</code></div>
</div>
</li>
<li><strong>Customization</strong>:
<ul>
<li>Modify the <code>url</code> variable to point to the site you want to visit.</li>
<li>Adjust the <code>visits</code> to define how many times the bot should visit the site.</li>
<li>Use the <code>interval</code> to set the time between each request (in seconds).</li>
</ul>
</li>
<li><strong>Execution</strong>: Save the code in a file, for example, <code>traffic_bot.py</code>, and run it:
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">python traffic_bot.py<br />
</code></div>
</div>
</li>
</ol>
<p>This basic bot simply visits a webpage multiple times, simulates traffic, and prints the request status.</p>
<p>The post <a href="https://cneris.com/en/traffic-bot-in-python/">Traffic Bot in Python</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/traffic-bot-in-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Detect Duplicate Links on a Website</title>
		<link>https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/</link>
					<comments>https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 02 Oct 2024 16:01:30 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[duplicated links]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[repeate links]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2321</guid>

					<description><![CDATA[<p>Detecting duplicate links on a website is important for SEO optimization and improving user experience. Here are several ways to achieve it: Using online tools: Tools like Screaming Frog or Ahrefs allow you to crawl all the links on a website and show you if there are any duplicates. Screaming Frog has a specific feature [...]</p>
<p>The post <a href="https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/">How to Detect Duplicate Links on a Website</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Detecting duplicate links on a website is important for SEO optimization and improving user experience. Here are several ways to achieve it:</p>
<ol>
<li><strong>Using online tools</strong>:
<ul>
<li>Tools like <strong>Screaming Frog</strong> or <strong>Ahrefs</strong> allow you to crawl all the links on a website and show you if there are any duplicates.</li>
<li><strong>Screaming Frog</strong> has a specific feature to track all internal and external links and find duplicates.</li>
</ul>
</li>
<li><strong>With custom scripts</strong>:
<ul>
<li>You can use a <strong>Python script</strong> with the <strong>BeautifulSoup</strong> library to extract all links and then check if any are duplicated.</li>
</ul>
<p>Example in Python:</p>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"><span class="hljs-keyword">import</span> requests<br />
<span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup<br />
<span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> Counter</code></code>url = <span class="hljs-string">&#8216;https://yoursite.com&#8217;</span><br />
response = requests.get(url)<br />
soup = BeautifulSoup(response.text, <span class="hljs-string">&#8216;html.parser&#8217;</span>)</p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code>links = [link.get(<span class="hljs-string">&#8216;href&#8217;</span>) <span class="hljs-keyword">for</span> link <span class="hljs-keyword">in</span> soup.find_all(<span class="hljs-string">&#8216;a&#8217;</span>) <span class="hljs-keyword">if</span> link.get(<span class="hljs-string">&#8216;href&#8217;</span>)]<br />
duplicates = [item <span class="hljs-keyword">for</span> item, count <span class="hljs-keyword">in</span> Counter(links).items() <span class="hljs-keyword">if</span> count &gt; <span class="hljs-number">1</span>]</p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code><span class="hljs-built_in">print</span>(<span class="hljs-string">f&#8217;Duplicate links: <span class="hljs-subst">{duplicates}</span>&#8216;</span>)</p>
</div>
</div>
</li>
<li><strong>Using browser extensions</strong>:
<ul>
<li>Some browser extensions like <strong>Check My Links</strong> for Chrome allow you to verify links on a page and detect if any are duplicated or broken.</li>
</ul>
</li>
</ol>
<p>The post <a href="https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/">How to Detect Duplicate Links on a Website</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Python script logging and posting in a Discuz forum</title>
		<link>https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/</link>
					<comments>https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 28 Sep 2024 15:45:22 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[python script]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2254</guid>

					<description><![CDATA[<p>#!/usr/bin/python3 # -*- coding: utf-8 -*- import logging import re import requests class AutoDiscuz: LOGIN_URL = "/member.php?mod=logging&amp;action=login&amp;loginsubmit=yes" LOGIN_POST = {"username": "", "password": ""} def __init__(self, forum_url, user_name, password): """初始化论坛 url、用户名、密码和代理服务器.""" self.forum_url = forum_url self.user_name = user_name self.password = password self.formhash = None self.is_login = False self.session = requests.Session() logging.basicConfig(level=logging.INFO, format="[%(levelname)1.1s %(asctime)s] %(message)s") def login(self): """登录论坛.""" [...]</p>
<p>The post <a href="https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/">Python script logging and posting in a Discuz forum</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>#!/usr/bin/python3<br />
# -*- coding: utf-8 -*-</p>
<p>import logging<br />
import re</p>
<p>import requests</p>
<p>class AutoDiscuz:<br />
LOGIN_URL = &#8220;/member.php?mod=logging&amp;action=login&amp;loginsubmit=yes&#8221;<br />
LOGIN_POST = {&#8220;username&#8221;: &#8220;&#8221;, &#8220;password&#8221;: &#8220;&#8221;}</p>
<p>def __init__(self, forum_url, user_name, password):<br />
&#8220;&#8221;&#8221;初始化论坛 url、用户名、密码和代理服务器.&#8221;&#8221;&#8221;<br />
self.forum_url = forum_url<br />
self.user_name = user_name<br />
self.password = password<br />
self.formhash = None<br />
self.is_login = False<br />
self.session = requests.Session()<br />
logging.basicConfig(level=logging.INFO,<br />
format=&#8221;[%(levelname)1.1s %(asctime)s] %(message)s&#8221;)</p>
<p>def login(self):<br />
&#8220;&#8221;&#8221;登录论坛.&#8221;&#8221;&#8221;<br />
url = self.forum_url + AutoDiscuz.LOGIN_URL<br />
AutoDiscuz.LOGIN_POST[&#8220;username&#8221;] = self.user_name<br />
AutoDiscuz.LOGIN_POST[&#8220;password&#8221;] = self.password<br />
req = self.session.post(url, data=AutoDiscuz.LOGIN_POST)<br />
if self.user_name in req.text:<br />
self.is_login = True<br />
if self.get_formhash():<br />
logging.info(&#8220;Login success!&#8221;)<br />
return<br />
logging.error(&#8220;Login faild!&#8221;)</p>
<p>def get_formhash(self):<br />
&#8220;&#8221;&#8221;获取 formhash.&#8221;&#8221;&#8221;<br />
req = self.session.get(self.forum_url)<br />
rows = re.findall(<br />
r&#8221;&lt;input type=\&#8221;hidden\&#8221; name=\&#8221;formhash\&#8221; value=\&#8221;(.*?)\&#8221; /&gt;&#8221;, req.text)<br />
if len(rows) != 0:<br />
self.formhash = rows[0]<br />
logging.info(&#8220;Formhash is: &#8221; + self.formhash)<br />
return True<br />
else:<br />
logging.error(&#8220;None formhash!&#8221;)<br />
return False</p>
<p>def reply(self, tid, subject=&#8221;&#8221;, msg=&#8221;6666666666666666666&#8243;):<br />
&#8220;&#8221;&#8221;回帖.&#8221;&#8221;&#8221;<br />
url = self.forum_url + \<br />
&#8220;/forum.php?mod=post&amp;action=reply&amp;replysubmit=yes&amp;inajax=1&amp;tid=&#8221; + \<br />
str(tid)<br />
post_data = {&#8220;formhash&#8221;: self.formhash,<br />
&#8220;message&#8221;: msg, &#8220;subject&#8221;: subject}<br />
content = self.session.post(url, post_data).text<br />
if &#8220;发布成功&#8221; in content:<br />
logging.info(&#8220;Tid: &#8221; + str(tid) + &#8221; reply success!&#8221;)<br />
return True<br />
else:<br />
logging.error(&#8220;Tid: &#8221; + str(tid) + &#8221; reply faild!&#8221;)<br />
return False</p>
<p>def main():<br />
auto_discuz = AutoDiscuz(&#8220;http://url&#8221;, &#8220;account&#8221;, &#8220;password&#8221;)<br />
auto_discuz.login()<br />
if auto_discuz.is_login:<br />
auto_discuz.reply(tid=1000)</p>
<p>if __name__ == &#8220;__main__&#8221;:<br />
main()</p>
<p>The post <a href="https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/">Python script logging and posting in a Discuz forum</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
	</channel>
</rss>
